NancyFx / Nancy.Bootstrappers.Ninject

Nancy boostrapper for the Ninject container
MIT License
17 stars 25 forks source link

Ninject binding issue with IDiagnosticsProvider #17

Open vatirim opened 10 years ago

vatirim commented 10 years ago

Hi,

it all worked when I used the Nancy internal IoC. With this lib I now get this exception:

A first chance exception of type 'Ninject.ActivationException' occurred in Ninject.dll Additional information: Error activating IntPtr No matching bindings are available, and the type is not self-bindable. Activation path: 4) Injection of dependency IntPtr into parameter method of constructor of type Func{IRouteCache} 3) Injection of dependency Func{IRouteCache} into parameter routeCacheFactory of constructor of type DefaultRouteCacheProvider 2) Injection of dependency IDiagnosticsProvider into parameter diagnosticProviders of constructor of type DefaultDiagnostics 1) Request for IDiagnostics

I am using the latest stable nuget packages:

I have a workaround. Injecting this bind in the bootstrapper:

protected override void ConfigureApplicationContainer(IKernel existingContainer)
{
  base.ConfigureApplicationContainer(existingContainer);
  existingContainer.Rebind<Func<IRouteCache>>().ToMethod(ctx =>
     () => ctx.Kernel.Get<IRouteCache>());
   // A Bind might be enough.
}

The problem might be that Ninject cannot inject into constructor parameters of type Func<Interface> as is the case in DefaultRouteCacheProvider.

Am I doing anything wrong or am I just the first to notice this?

danbarua commented 9 years ago

Try this

kernel.Load<Nancy.Bootstrappers.Ninject.FactoryModule>();

From here https://groups.google.com/forum/#!topic/nancy-web-framework/-d4g3D-o_-w

ZeVS777 commented 8 years ago

danbarua, your phrase must be in documentation of this project! Thank you!