只是想分享我怎么解决它使用Visual Studio 2008
对于那些你们去过www.tekpub.com的代码有点儿熟悉,是的!下面您正确的代码是从掌握ASP.NET MVC 2.0系列,以及如何使用NLOG
最少报名参考的演示:
- Ninject.dll
- Ninject.Web
- NLOG .DLL
的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>
部分正确。我知道扩展ninject.web,但不知道如何在现有的asp.net web应用程序上实现它。 – 2010-06-25 02:48:32
@No正文:http://davidhayden.com/blog/dave/archive/2008/06/20/ninjectdependencyinjectionaspnetwebpagessample.aspx涵盖了它的相当不错 - 有一个基础类的全球和页面。有没有没有涵盖的东西?如果有,问。 – 2010-06-25 07:57:17
公平,但最后,海登使用Ninject.Framework.Web这是一样的新ninject.web? – 2010-06-25 10:03:13