我所看到的是类似于下面(http://github.com/ninject/ninject.web.mvc)的内容:
README.markdown
这个扩展允许尼尼姆核心和ASP.NET MVC项目之间的集成。要使用它,只需使HttpApplication (通常在Global.asax.cs中)扩展NinjectHttpApplication:
公共类YourWebApplication : NinjectHttpApplication { public覆盖void () { //这仅在RegisterAllControllersIn("Some.Assembly.Name");MVC1 }中需要 公共覆盖IKernel CreateKernel() {返回新StandardKernel(新的SomeModule()、新的SomeOtherModule()、.); // OR,自动加载模块: var内核=新的StandardKernel();kernel.AutoLoadModules("~/bin");返回内核;}
完成此操作后,控制器将通过Ninject被激活,这意味着您可以公开对其构造函数(或属性或方法)的依赖关系,以请求注入。
发布于 2010-06-23 10:00:01
因为你在问题中没有排除这一点,我不得不假设你没有意识到与您引用的WebForms等价的
(从主站点上的Ninject扩展索引链接)
发布于 2010-06-29 03:12:50
只是想分享一下我是如何用2008解决它的
对于你们这些人来说,下面的www.tekpub.com代码是很熟悉的,是的!下面正确的代码来自精通ASP.NET MVC 2.0系列,以及如何使用NLog的演示
需要参考:
Global.asax :
<%@ Application Language="C#" Inherits ="Ninject.Web.NinjectHttpApplication" %>
<%@ Import Namespace="App_Code.Infrastructure.Logging"%>
<%@ Import Namespace="Ninject.Modules"%>
<%@ Import Namespace="Ninject"%>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
protected override void OnApplicationStarted()
{
//base.OnApplicationStarted();
Container.Get<ILogger>().Info("Application Started");
}
protected override IKernel CreateKernel()
{
return Container;
}
static IKernel Container
{
get
{
return new StandardKernel(new SiteModule());
}
}
class SiteModule : NinjectModule
{
public override void Load()
{
Bind<ILogger>().To<NLogger>().InSingletonScope();
}
}
</script>https://stackoverflow.com/questions/3059187
复制相似问题