只是想分享我怎麼解決它使用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