Using Ninject 2.0 with ASP.Net 3.5

I am trying to use Ninject 2.0 with an Asp.NET 3.5 web application. The following are the DLLS and its versions that I use.

  • Ninject.dll - v2.0.0.0
  • Ninject.Extensions.Logging.dll v2.0.0.0
  • Ninject.Web.dll v1.0.0.0

In my global.ascx.cs, I have the following method.

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

When I run the application, I get the following error.

Error activating ILoggerFactory
No matching bindings are available, and the type is not self-bindable.
Activation path:
 1) Request for ILoggerFactory

Suggestions:
 1) Ensure that you have defined a binding for ILoggerFactory.
 2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.
 3) Ensure you have not accidentally created more than one kernel.
 4) If you are using automatic module loading, ensure the search path and filters are

correctly.

I do not understand, although I am not trying to register Logger, it seems he is trying to create it. How can I fix this error? Should I use any of the Ninject extension registrars?

Thanks GK

+3
source share
2 answers

, - Ninject ILoggerFactory . , , , - ASP.Net WebForms, ASP.Net MVC.

PageBase, , - Ninject. :

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

, , Ninject . , ILoggerFactory, ILogger ; , , - IDataAccess. , . , NLog Log4Net. , Log4Net, CreateKernel :

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

, using Ninject.Extensions.Logging.Log4net;.

( ), - Ninject. , ILoggerFactory ILogger, (.. "" ) ILoggerFactory.

+6

. ddls log4net.dll, ninject.extensions.logging.dll, ninject.extensions.log4net.dd, ningject.web.dll ninject.dll . , - log4net.dll.

+1

Source: https://habr.com/ru/post/1734662/


All Articles