Incorrect dependencies resolving inside child Autofac lifetime scope #48
Comments
Hey @alex-training It seems to be related to how Modules are used within updated containers in child scopes. I'll let you know once i find something more concrete though |
Yep, it appears that modules within child scopes are not handled as expected within autofac. Github issue here. I'm not sure we can do much ourselves here as this touches very deeply with autofac internals. A quick fix is to re-register the module whenever you create a new livetimescope: endpointConfiguration.UseContainer<AutofacBuilder>(
customizations: customizations =>
{
var childScope = _container.BeginLifetimeScope(b => b.RegisterModule<NLogModule>());
customizations.ExistingLifetimeScope(childScope); // THIS LINE DOESN'T WORK PROPERLY
//customizations.ExistingLifetimeScope(_container); // THIS LINE WORKS
}); |
Hey @WilliamBZA |
Great, I'm going to close this in the meantime. By the way, we have a sample showing NLog integration that doesn't require an Autofac module. It uses a community port for NLog that @SimonCropp created. |
Oops! It's not community port anymore, it's officially supported. |
Hi @WilliamBZA, That's a cool sample, indeed. |
Hi guys!
I'm trying to host multiple NServiceBus endpoints in my custom self-written host, so I was thinking about creating a child Autofac lifetime scope per endpoint.
For some reason such approach doesn't work and I'm getting errors while resolving dependencies for my message handlers.
Probably I can use a root container everywhere instead, but I'm afraid about endpoints isolation.
Something like this:
What I'm doing wrong?
Could you guys please help with some advice?
I've created a sample to demonstrate the issue:
a sample
Many thanks
The text was updated successfully, but these errors were encountered: