Using Ninject 2.0 with ASP .Net 3.5

╄→尐↘猪︶ㄣ 提交于 2019-12-04 13:07:12

The error indicates that somewhere, Ninject is trying to resolve the ILoggerFactory interface to a concrete class. Based on what you've stated as your references above, it sounds like you're ASP.Net web app is WebForms-based rather than an ASP.Net MVC app.

With that in mind, your pages should be derived from PageBase which is an abstract class provided by the Ninject web library. That class has the following property definition:

[Inject]
public ILogger Logger { get; set; }

Therefore, when your page is instantiated, Ninject is trying to inject a logger into the property on the page. As the error alludes to, you need a binding defined for the ILoggerFactory as well as ILogger; however, the only binding you've provided is for IDataAccess. You need to load one of the modules defined in the logging extensions library as well. I believe you can choose between NLog and Log4Net. So, for example, if you want to use Log4Net, your CreateKernel function would look like this:

protected override IKernel CreateKernel()
{
    IKernel kernel = new StandardKernel(new Log4netModule());            
    kernel.Bind<IDataAccess>().To<DataAccessEntBlock>().InSingletonScope();
    return kernel;
}

This assumes you have a using Ninject.Extensions.Logging.Log4net; statement in the file.

In either case, you've got to select a logger and load it's bindings (via the module) as the Ninject Web library requires it. If you don't have any logging concerns right now, you could opt to provide implementations of ILoggerFactory and ILogger that do nothing (i.e. a "null" logger) and bind the your dummy ILoggerFactory yourself.

i had the same problem too. try referencing ddls again log4net.dll, ninject.extensions.logging.dll, ninject.extensions.log4net.dd, ningject.web.dll and ninject.dll this solved my problem. most probably due to old log4net.dll.

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