2015-08-08 12 views
6

ich ASP.NET vNext beta6 gewechselt haben erkannt wurde und begann, die folgende Ausnahme zu erhalten versucht, meine Anwendung auszuführen:ASP.NET vNext und Ninject Eine zyklische Abhängigkeit zwischen den Konstrukteuren von zwei Dienste

Ninject.ActivationException: Error activating IOptions{MvcJsonOptions} using binding from IOptions{TOptions} to OptionsManager{TOptions} 
A cyclical dependency was detected between the constructors of two services. 

Activation path: 
    4) Injection of dependency IOptions{MvcJsonOptions} into parameter jsonOptions of constructor of type MvcJsonMvcOptionsSetup 
    3) Injection of dependency IConfigureOptions{MvcOptions} into parameter setups of constructor of type OptionsManager{MvcOptions} 
    2) Injection of dependency IOptions{MvcOptions} into parameter optionsAccessor of constructor of type ControllerActionDescriptorProvider 
    1) Request for IActionDescriptorProvider 

Suggestions: 
    1) Ensure that you have not declared a dependency for IOptions{MvcJsonOptions} 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() 
    at Ninject.KernelBase.<>c__DisplayClass15.<Resolve>b__f(IBinding binding) 
    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) 
    at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent) 
    at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) 
    at Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target) 
    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) 
    at Ninject.Activation.Context.ResolveInternal(Object scope) 
    at Ninject.Activation.Context.Resolve() 
    at Ninject.KernelBase.<>c__DisplayClass15.<Resolve>b__f(IBinding binding) 
    at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext() 
    at System.Linq.Enumerable.<CastIterator>d__1`1.MoveNext() 
    at System.Linq.Buffer`1..ctor(IEnumerable`1 source) 
    at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext() 
    at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func) 
    at Microsoft.Framework.OptionsModel.OptionsManager`1.Configure(String optionsName) 
    at Microsoft.Framework.OptionsModel.OptionsManager`1.GetNamedOptions(String name) 
    at Microsoft.Framework.OptionsModel.OptionsManager`1.get_Options() 
    at Microsoft.AspNet.Mvc.ApplicationModels.DefaultApplicationModelProvider..ctor(IOptions`1 mvcOptionsAccessor) 
    at DynamicInjector17db4d7dd8164be68f856c18b6811a3a(Object[]) 
    at Ninject.Activation.Providers.StandardProvider.Create(IContext context) 
    at Ninject.Activation.Context.ResolveInternal(Object scope) 
    at Ninject.Activation.Context.Resolve() 
    at Ninject.KernelBase.<>c__DisplayClass15.<Resolve>b__f(IBinding binding) 
    at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext() 
    at System.Linq.Enumerable.<CastIterator>d__1`1.MoveNext() 
    at System.Linq.Buffer`1..ctor(IEnumerable`1 source) 
    at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext() 
    at System.Linq.Buffer`1..ctor(IEnumerable`1 source) 
    at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) 
    at Microsoft.AspNet.Mvc.Core.ControllerActionDescriptorProvider..ctor(IControllerTypeProvider controllerTypeProvider, IEnumerable`1 applicationModelProviders, IOptions`1 optionsAccessor) 
    at DynamicInjectorb26d26f3e9ae47cf8e8c7234b167fb59(Object[]) 
    at Ninject.Activation.Providers.StandardProvider.Create(IContext context) 
    at Ninject.Activation.Context.ResolveInternal(Object scope) 
    at Ninject.Activation.Context.Resolve() 
    at Ninject.KernelBase.<>c__DisplayClass15.<Resolve>b__f(IBinding binding) 
    at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext() 
    at System.Linq.Enumerable.<CastIterator>d__1`1.MoveNext() 
    at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source) 
    at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredServices[T](IServiceProvider provider) 
    at Microsoft.AspNet.Mvc.Core.DefaultActionDescriptorsCollectionProvider.GetCollection() 
    at Microsoft.AspNet.Mvc.Core.DefaultActionDescriptorsCollectionProvider.get_ActionDescriptors() 
    at Microsoft.AspNet.Mvc.Routing.AttributeRoute.GetInnerRoute() 
    at Microsoft.AspNet.Mvc.Routing.AttributeRoute.RouteAsync(RouteContext context) 
    at Microsoft.AspNet.Routing.RouteCollection.<RouteAsync>d__9.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 System.Runtime.CompilerServices.TaskAwaiter.GetResult() 
    at Microsoft.AspNet.Builder.RouterMiddleware.<Invoke>d__4.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 System.Runtime.CompilerServices.TaskAwaiter.GetResult() 
    at Microsoft.AspNet.Diagnostics.ErrorHandlerMiddleware.<Invoke>d__5.MoveNext() 

Bitte beachte, dass ich verwende NinjectServiceProvider von offiziellen asp.net dependency injection repository.

Kann jemand dieses Problem beheben?

+0

@mason Ich verwende keine der in dem Fehler genannten Abhängigkeiten. Ich glaube, dass der Fehler aus einer der Bindungen in service.AddMvc() hervorgeht, die von asp.net-Team gesteuert wird. Ich dachte nur, dass jemand das selbe Problem bereits gefunden hat und die Lösung gefunden hat. –

+3

Pflege erklären Down-Vote? –

+1

Ich habe dieses Problem jetzt mit beta6; Hast du eine Lösung gefunden oder ist das möglicherweise ein Bug in beta6? –

Antwort

1

Ich weiß, das ist spät, aber ich habe dieses Problem gelöst. Ich glaube, das ist indirekt mit dieser issue verbunden. Im Wesentlichen war die erkannte zyklische Abhängigkeit wirklich ein Ninject-Bug.

Also ich weiß, dieses Problem ist in Ninject 4.0.0-beta-0134 gelöst, obwohl ich nicht sicher, ob die genaue Commit als CI history begrenzt hat. There also isn't a tag within the Git Repo. Es ist nicht gelöst in Ninject 3.2.3-unstable-012.

Weitere Informationen finden Sie unter here.