相关疑难解决方法(0)

使用Asp.Net MVC和Web Api配置Ninject

我已经设置了我的项目Ninject IoC.
我的项目有常规Asp.Net MVC控制器和Web Api控制器.现在,Ninject使用Web ApiNinject不适用于常规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

37
推荐指数
4
解决办法
5万
查看次数

Ninject和OnePerRequestModule

我最近尝试了NinjectNinject.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)

我的问题如下......

  • 什么是 OnePerRequestModule
  • 为什么多次调用此构造函数?
  • StartManaging如果构造函数被多次调用,那么此方法的目的是什么?

ninject ninject-extensions asp.net-mvc-3

12
推荐指数
1
解决办法
2981
查看次数