Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Ninject gives a cyclical dependency error with MVC #134

Closed
Tragetaschen opened this issue Nov 7, 2014 · 2 comments
Closed

Ninject gives a cyclical dependency error with MVC #134

Tragetaschen opened this issue Nov 7, 2014 · 2 comments

Comments

@Tragetaschen
Copy link

Steps to reproduce: Add the following code in an empty vNext (alpha4) Startup.Configure method:

var services = new ServiceCollection();
services.AddMvc();
services.Add(OptionsServices.GetDefaultServices());

var kernel = new StandardKernel();
NinjectRegistration.Populate(kernel, services, app.ApplicationServices);

app.UseServices(kernel.Get<IServiceProvider>());

app.UseMvc();

This gives a 500 startup error:

A cyclical dependency was detected between the constructors of two services.
Activation path:
4) Injection of dependency INestedProviderManager{FilterProviderContext} into parameter filterProvider of constructor of type ReflectedActionInvokerProvider
3) Injection of dependency INestedProvider{ActionInvokerProviderContext} into parameter providers of constructor of type NestedProviderManager{ActionInvokerProviderContext}
2) Injection of dependency INestedProviderManager{ActionInvokerProviderContext} into parameter actionInvokerProvider of constructor of type ActionInvokerFactory
1) Request for IActionInvokerFactory
@halter73
Copy link
Member

This actually seems to be an issue with Ninject itself. I reported the issue a couple of months back when I first tried using MVC with Ninject:

ninject/Ninject#143

You can workaround this issue in the meantime by manually registering INestedProviderManager<FilterProviderContext> explicitly as NestedProviderManager<FilterProviderContext>:

kernel.Populate(services, app.ApplicationServices);
kernel.Bind<INestedProviderManager<FilterProviderContext>>().To<NestedProviderManager<FilterProviderContext>>();

This will stop Ninject from falsely identifying a circular dependency in the open generic registration MVC makes for INestedProviderManager<>.

@halter73
Copy link
Member

We are already tracking this issue in the MVC repo, so I think we can close the issue here.

aspnet/Mvc#953

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants