Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

NancyModule.Context null when attempting to register all modules at startup with Autofac 4 #51

Open
gkinsman opened this issue Sep 15, 2016 · 0 comments

Comments

@gkinsman
Copy link

Hi,

I've run into an issue that appears to be new with Autofac 4. When Nancy calls GetAllModules at startup to register each module's routes, it fails in the getter of NancyModule.Request as the Context in that instance is null.

Given that I'm registering my modules like this with properties autowired, it could be that a change to property wiring in Autofac has broken this registration. Not sure!

 builder.RegisterAssemblyTypes(typeof(AppNancyBootstrapper).Assembly)
                .AsSelf()
                .As<INancyModule>()
                .PropertiesAutowired(PropertyWiringOptions.PreserveSetValues);

Stack Trace:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Something went wrong when trying to satisfy one of the dependencies during composition, make sure that you've registered all new dependencies in the container and inspect the innerexception for more details. ---> 

Autofac.Core.DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = NancyEngine (ReflectionActivator), Services = [Nancy.INancyEngine], Lifetime = Autofac.Core.Lifetime.RootScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> 


An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = DefaultRequestDispatcher (ReflectionActivator), Services = [Nancy.Routing.IRequestDispatcher], Lifetime = Autofac.Core.Lifetime.RootScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> 


An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = DefaultRouteResolver (ReflectionActivator), Services = [Nancy.Routing.IRouteResolver], Lifetime = Autofac.Core.Lifetime.RootScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> 


An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = RouteCache (ReflectionActivator), Services = [Nancy.Routing.IRouteCache], Lifetime = Autofac.Core.Lifetime.RootScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> 


An exception was thrown while invoking the constructor 'Void .ctor(Nancy.INancyModuleCatalog, Nancy.INancyContextFactory, Nancy.Routing.IRouteSegmentExtractor, Nancy.Routing.IRouteDescriptionProvider, Nancy.Culture.ICultureService, System.Collections.Generic.IEnumerable`1[Nancy.Routing.IRouteMetadataProvider])' on type 'RouteCache'. ---> 


An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = INancyModule[] (DelegateActivator), Services = [System.Collections.Generic.IEnumerable`1[[Nancy.INancyModule, Nancy, Version=1.4.1.0, Culture=neutral, PublicKeyToken=null]]], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> 


An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = INancyModule[] (DelegateActivator), Services = [System.Collections.Generic.IEnumerable`1[[Nancy.INancyModule, Nancy, Version=1.4.1.0, Culture=neutral, PublicKeyToken=null]]], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> 

and so on and so on...

I've downgraded to Autofac 3.x for now as a workaround.

Thanks!

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

1 participant