Ninject with ASP.Net webforms and MVC

后端 未结 3 568
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-09 08:28

I want to use Ninject in a project which combines ASP.Net webforms and ASP.Net MVC. I\'m using Ninject 2, but when I use NinjectHttpApplication from Ninject.Web.Mvc it complains

3条回答
  •  我在风中等你
    2021-02-09 08:54

    As Ruben told, I've put up a message on the Ninject Mailing list:

    http://groups.google.com/group/ninject/browse_thread/thread/317fc48387399aa6

    The answer in short is, it unfortunately isn't really possible. However with a custom PageBase class you can make Property and Method injection possible (from Nate Kohari's answer in the Ninject Mailing List):

    public abstract class PageBase : Page
    {
      public IKernel Kernel { get; private set; }
      public PageBase() { Kernel = ...; }
      public void Page_Init() { Kernel.Inject(this); }
    } 
    

提交回复
热议问题