Rod*_*eek 7 asp.net asp.net-mvc webforms ninject
我想在一个结合ASP.Net webforms和ASP.Net MVC的项目中使用Ninject.我正在使用Ninject 2,但是当我使用来自Ninject.Web.Mvc的NinjectHttpApplication时,当我使用类似于PageBase的东西而没有创建内核时,它就会抱怨.
我在Global.asax中有以下内容,我不确定要添加什么.
public class MvcApplication : Ninject.Web.Mvc.NinjectHttpApplication
{
protected override void OnApplicationStarted()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
RegisterAllControllersIn(Assembly.GetExecutingAssembly());
}
protected override Ninject.IKernel CreateKernel()
{
return new StandardKernel(new ServiceModule());
}
}
Run Code Online (Sandbox Code Playgroud)
有人在某个地方工作,可以分享一些想法或代码吗?
正如 Ruben 所说,我已经在 Ninject 邮件列表上发布了一条消息:
http://groups.google.com/group/ninject/browse_thread/thread/317fc48387399aa6
简而言之,答案是,不幸的是,这实际上是不可能的。然而,使用自定义 PageBase 类,您可以使属性和方法注入成为可能(来自 Ninject 邮件列表中 Nate Kohari 的回答):
public abstract class PageBase : Page
{
public IKernel Kernel { get; private set; }
public PageBase() { Kernel = ...; }
public void Page_Init() { Kernel.Inject(this); }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1951 次 |
| 最近记录: |