我已经设置了我的项目Ninject IoC.
我的项目有常规Asp.Net MVC控制器和Web Api控制器.现在,Ninject使用Web Api但Ninject不适用于常规Asp.MVC控制器.
我的常规MVC控制器实现;
public class GalleryController : BaseController
{
public GalleryController(IUow uow)
{
Uow = uow;
}
........
}
Run Code Online (Sandbox Code Playgroud)
与常规控制器一起使用时出错
An error occurred when trying to create a controller of type 'Web.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.]
Run Code Online (Sandbox Code Playgroud)
但是,当我使用Web Api尝试相同的代码时,它可以工作
public class GalleryController : BaseApiController
{
public GalleryController(IUow uow)
{
Uow = …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc dependency-injection ninject repository-pattern
我最近尝试了Ninject与Ninject.Web.Mvc扩展,我已经发现了一些奇特的和,而不是突破,令人目不暇接.
在NinjectHttpApplication抽象类中,有一个构造函数定义如下..
/// <summary>
/// Initializes a new instance of the <see cref="NinjectHttpApplication"/> class.
/// </summary>
protected NinjectHttpApplication()
{
this.onePerRequestModule = new OnePerRequestModule();
this.onePerRequestModule.Init(this);
}
Run Code Online (Sandbox Code Playgroud)
我在这里放置了一个调试器断点,这会被调用几次.我找不到任何真实的文档.在实现代码中,有这条线引起了我的注意.
if (kernel.Settings.Get("ReleaseScopeAtRequestEnd", true))
{
OnePerRequestModule.StartManaging(kernel);
}
Run Code Online (Sandbox Code Playgroud)
我的问题如下......
OnePerRequestModuleStartManaging如果构造函数被多次调用,那么此方法的目的是什么?