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

MvcServices.GetDefaultServices breaks Ninject #953

Closed
halter73 opened this issue Aug 7, 2014 · 2 comments
Closed

MvcServices.GetDefaultServices breaks Ninject #953

halter73 opened this issue Aug 7, 2014 · 2 comments
Assignees
Milestone

Comments

@halter73
Copy link
Member

halter73 commented Aug 7, 2014

There is a Ninject issue that makes it unable to resolve INestedProviderManager<ActionInvokerProviderContext> because it incorrectly identifies a cyclical dependency.

It's possible to work around this issue by either adding INestedProviderManager<ActionInvokerProviderContext> or INestedProviderManager<FilterProviderContext> as a closed generic service in MvcServices.GetDefaultServices.

Currently, I get the following exception when trying to run the MVC sample in the dev branch with Ninject:

Ninject.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 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

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.

 at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:line 148
 at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 386
 at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
 at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
 at Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent) in c:\Projects\Ninject\ninject\src\Ninject\Planning\Targets\Target.cs:line 197
 at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent) in c:\Projects\Ninject\ninject\src\Ninject\Planning\Targets\Target.cs:line 165
 at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 114
 at Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96
 at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
 at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
 at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
 at Ninject.Activation.Providers.StandardProvider.Create(IContext context) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96
 at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:line 157
 at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 386
 at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
 at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
 at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
 at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext()
 at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
 at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
 at Microsoft.Framework.DependencyInjection.NestedProviders.NestedProviderManager`1..ctor(IEnumerable`1 providers)
 at DynamicInjector51731b6e402f4dbbafb8c36a24eb0839(Object[] )
 at Ninject.Activation.Providers.StandardProvider.Create(IContext context) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96
 at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:line 157
 at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 386
 at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
 at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
 at Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent) in c:\Projects\Ninject\ninject\src\Ninject\Planning\Targets\Target.cs:line 197
 at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent) in c:\Projects\Ninject\ninject\src\Ninject\Planning\Targets\Target.cs:line 165
 at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 114
 at Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96
 at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
 at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
 at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
 at Ninject.Activation.Providers.StandardProvider.Create(IContext context) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96
 at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:line 157
 at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 386
 at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
 at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
 at Microsoft.Framework.DependencyInjection.Ninject.NinjectServiceProvider.GetLast(IEnumerable services)
 at Microsoft.Framework.DependencyInjection.Ninject.NinjectServiceProvider.GetService(Type type)
 at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetService[T](IServiceProvider provider)
 at Microsoft.AspNet.Mvc.MvcRouteHandler.<RouteAsync>d__1.MoveNext() in F:\dev\Universe\Mvc\src\Microsoft.AspNet.Mvc.Core\MvcRouteHandler.cs:line 77
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.AspNet.Routing.Template.TemplateRoute.<RouteAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.AspNet.Routing.RouteCollection.<RouteAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.AspNet.Builder.RouterMiddleware.<Invoke>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.AspNet.RequestContainer.ContainerMiddleware.<Invoke>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.AspNet.Loader.IIS.KlrHttpApplication.<ProcessRequestAsyncImpl>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.AspNet.Loader.IIS.HttpApplicationBase.<InvokeProcessRequestAsyncImpl>d__1.MoveNext()
``
@yishaigalatzer
Copy link
Contributor

ninject/Ninject#143

We should just keep this bug around and verify when ninject fixes it.

@yishaigalatzer
Copy link
Contributor

The issue in this particular bug is addressed by b12c4c5. However similar uses of open generics will still break ninject. This could come from users code as well as other framework code

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

No branches or pull requests

3 participants