views:

410

answers:

1

The officially released Ninject 2 no longer includes reference to the WebForms-specific functionality for IoC for WebForms, MasterPages, etc. It's now separated out into plugins/extensions; which in this case is the http://github.com/idavis/ninject.web extension. My problem however is that there's a dependency on log4net (or NLog) and I can't find any documentation on how to configure it to either integrate with my current log4net configuration, or remove it altogether (i.e. set the logging to null so I don't conceivably have two log4net configurations running).

http://markmail.org/message/7iv7nltanz6ve4ga#query:Error%20activating%20ILoggerFactory%20ninject.web+page:1+mid:6o4q6ee2js2k4gfp+state:results references others with the same issue, but again, no real documentation on what to do with it. I've looked through the source for all of it, and must be missing something obvious.

Can anyone point me in the right direction for the best way of dealing with this so I can still easily integrate Ninject with WebForms, but not have extraneous logging services running? Or not worry about something like the following on the Global.asax:

    protected override IKernel CreateKernel()
    {
        IKernel kernel =
        new StandardKernel(new SomeMyModule(), new Log4netModule());
        return kernel;
    }

I'm currently kickstarting my log4net configuration in global.asax via

 private readonly static ILog Log = LogManager.GetLogger(typeof(Global));:
A: 

While Ninject.Web has ILogger properties, it does not log anything.

If you want to disable Ninject.Extensions.Logging entirely, create and bind an implementation of ILoggerFactory that returns null from all methods.

Or if you want to enable it with log4net, fetch Ninject.Extensions.Logging from ninject.org and reference Ninject.Extensions.Logging.Log4net from your project. It will be automatically loaded by Ninject 2.0.

If you are building Ninject.Web from source, you could remove the logging extension by:

  • drop the reference to that assembly
  • remove the ILogger member from the 5 classes that have it
Lachlan Roche
"It will be automatically loaded by Ninject 2.0" are the magic words in that it uses my already existing log4net configuration.
Ted