Nancy.Bootstrappers.Ninject icon indicating copy to clipboard operation
Nancy.Bootstrappers.Ninject copied to clipboard

Ninject binding issue with IDiagnosticsProvider

Open vatirim opened this issue 10 years ago • 2 comments

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:

  • Nancy 0.23.2
  • Nancy.Bootstrappers.Ninject 0.23.2
  • Ninject 3.0.1.10
  • Ninject.Extensions.ChildKernel 3.0.0.5

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?

vatirim avatar Oct 06 '14 08:10 vatirim

Try this

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

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

danbarua avatar Dec 30 '14 10:12 danbarua

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

ZeVS777 avatar Nov 08 '16 22:11 ZeVS777