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

Attempting to use Music Store with Ninject results in cyclic dependency error #153

Closed
ajcvickers opened this issue Dec 11, 2014 · 1 comment

Comments

@ajcvickers
Copy link

See dotnet/efcore#1241. When removing this line in Startup.cs

SampleData.InitializeMusicStoreDatabaseAsync(app.ApplicationServices).Wait();

which is not needed if the database exists, the result is this exception:

An unhandled exception occurred while processing the request.

ActivationException: Error activating INestedProviderManager{FilterProviderContext} using binding from INestedProviderManager{T} to NestedProviderManager{T}
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 ControllerActionInvokerProvider
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

Suggestions:
1) Ensure that you have not declared a dependency for INestedProviderManager{FilterProviderContext} on any implementations of the service.
2) Consider combining the services into a single one to remove the cycle.
3) Use property injection instead of constructor injection, and implement IInitializable
if you need initialization logic to be run after property values have been injected.
Ninject.Activation.Context.Resolve() in Context.cs, line 148

Stack Query Cookies Headers Environment
ActivationException: Error activating INestedProviderManager{FilterProviderContext} using binding from INestedProviderManager{T} to NestedProviderManager{T} 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 ControllerActionInvokerProvider 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 Suggestions: 1) Ensure that you have not declared a dependency for INestedProviderManager{FilterProviderContext} on any implementations of the service. 2) Consider combining the services into a single one to remove the cycle. 3) Use property injection instead of constructor injection, and implement IInitializable if you need initialization logic to be run after property values have been injected.
Ninject.Activation.Context.Resolve() in Context.cs
Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding) in KernelBase.cs
System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent) in Target.cs
Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent) in Target.cs
Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) in StandardProvider.cs
Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target) in StandardProvider.cs
System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
System.Linq.Buffer`1..ctor(IEnumerable`1 source)
System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
Ninject.Activation.Providers.StandardProvider.Create(IContext context) in StandardProvider.cs
Ninject.Activation.Context.Resolve() in Context.cs
Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding) in KernelBase.cs
System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
System.Linq.Buffer`1..ctor(IEnumerable`1 source)
System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext()
System.Linq.Buffer`1..ctor(IEnumerable`1 source)
System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
Microsoft.Framework.DependencyInjection.NestedProviders.NestedProviderManager`1..ctor(IEnumerable`1 providers)
DynamicInjector2649713f7ca34ec59941a8ccba28b9b4(Object[] )
Ninject.Activation.Providers.StandardProvider.Create(IContext context) in StandardProvider.cs
Ninject.Activation.Context.Resolve() in Context.cs
Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding) in KernelBase.cs
System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent) in Target.cs
Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent) in Target.cs
Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) in StandardProvider.cs
Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target) in StandardProvider.cs
System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
System.Linq.Buffer`1..ctor(IEnumerable`1 source)
System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
Ninject.Activation.Providers.StandardProvider.Create(IContext context) in StandardProvider.cs
@halter73
Copy link
Member

This is a Ninject bug. I filed an issue on Ninject's github repo a few months ago.

I also filed another issue on the MVC repo to track the progress.

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

3 participants