When should one use Kernel.BeginBlock() in Ninject.MVC3

£可爱£侵袭症+ 提交于 2019-12-05 21:34:41

Remo Gloor says that the ActivationBlock concept is broken and that you should not use them. Furthermore, issues regarding ActivationBlock will most likely not going to be fixed, as the feature is to be removed from future Ninject versions.

The idea of Activation Blocks (current implementation) is:

  • Create exactly one instance of every type requested in the ActivationBlock
  • dispose of all instances created by the ActivationBlock when the block itself is disposed.

Also see:

Furthermore, you've tagged & named your question with "MVC3" but the System.Web.Http.Dependencies.IDependencyResolver interface you are using is related to asp.net-web-api. MVC's System.Web.Mvc.IDependencyResolver is different.

Ninject already features nuget packages which do the integration into asp.net-mvc-3 (4,5,...) and asp.net web api:

Now if you really want to implement the dependency resolver and scope yourself we can compare it to ninject's web-api implementation:

The only real difference to your code is that they have one class implementing both, IDependencyResolver and IDependencyScope and that they are consistently using the IResolutionRoot instead of the IKernel interface.

(and for comparison: MVC3 NinjectDependencyResolver.cs)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!