Ninject with ASP.Net webforms and MVC

核能气质少年 提交于 2019-12-03 07:17:09

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); }
} 

1) Have a look in the source for both the Mvc and non-Mvc Ninject Extensions - the code is very short and neat

2) Go to the ninject mailing list and ask this question, together with what you've learned from the source. There'll be an answer or a patch lightening quick

here are some very good resources on how to leverage DI in webforms that I had bookmarked some time ago:

http://aspnetresources.com/articles/ioc_and_di_with_web_forms http://aspnetresources.com/articles/real_world_ioc_and_di_with_webforms

Hope this helps.

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