New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AutoActivate / IStartable doesn't work for components configured within a LifetimeScope #567
Comments
Stumbled on this a day ago too! |
I ran into this as well, does IStartable also not work? |
I ran into something similar while using the AutofacNancyBootstrapper. The hooks to configure the container look like: The most discoverable way to update the registrations is: However, you can work around the problem by casting the ILifetimeScope to an IContainer: This gets an overload which does call StartStartableComponents. It's relying on an implementation detail, but unfortunately I'm not sure if the problem is with Autofac, or with Nancy's hook - which should provide an IContainer instead of an ILifetimeScope. I suspect the latter, but if Nancy fixed that, it would be a very breaking change. Perhaps Autofac should complain about an AutoActivate registration made against a component registry (instead of a container)? At least it would be an explicit error, instead of just having AutoActivate registrations mysteriously not work. |
A bit of an update, it seems like this is sort of by design as the documentation does say.
Although I don't see anything that would technically stop registrations that use Currently after I create a new @Rophuine therefore an explicit error would break this |
Yeah, I had a suspicion that any solution proposed would risk breaking existing hacks around the behaviour. Given that AutoActivate is a thing which happens on container build instead of scope creation, I'd suggest coming up with an alternative marker that something should be started on creation of a scope - implement a new interface (something like IActivatesOnBeginLifetimeScope) and then just resolve an IEnumerable of those. Breaking changes are rare, but you would be protecting yourself against any future breaking changes designed to prevent people running into this issue. |
@Rophuine I could see this going the other way as well though
|
From #731: Assume I have these registrations:
Instead they should be activated when beginning scopes:
So I expect |
Why did this issue was closed? It's bug, because current implementation of Autoactivate will fail on registration with InstancePerMatchingLifetimeScope in any case, it should not be designed behaviour |
If you look at the issue history, it was closed via a commit that fixes the issue. It will be released in an upcoming version. |
@tillig , the commit was added almost a year ago and still not released? Whattt? |
It's in the 4.9.0 beta that's out there right now. [So, I guess, correction to my earlier statement - it's released, just in beta.] We've asked for feedback on that beta because it adds a bunch of new stuff like a new way to handle decorators and some memory/locking improvements. It's a long beta to make sure all the improvements and changes work well together. Feel free to try the beta and let us know what you think. We don't get much feedback on these things until we break someone in some horrible way and then it's kinda too late, right? Otherwise, thanks for your patience as the two unpaid project maintainers do the best we can to get things out here. If you're ever interested in helping us speed things up we also put a call for extension project owners out there almost a year ago with zero takers so far. If we can get people to own more of the extensions, we can spend more time focusing on larger core things. |
In 4.9.2 the issue is still presented. |
Tests for the issue here still pass. If you've found something new/additional, please file a new issue with a failing unit test repro so we can better address it. |
I've encountered a problem with auto activation of components specifically configured only during creation of a LifetimeScope. Like in the example below:
https://gist.github.com/llaszko/4143edda2eb7a8118e54
it looks like ContainerBuilder.StartStartableComponents isn't called by an overload of ContainerBuilder.Update called during the LifetimeScope creation.
I think it would be nice to at least have public access to ContainerBuilder.StartStartableComponents or ideally allow components specifically configured in a dependent scope to support AutoActivate properly.
The text was updated successfully, but these errors were encountered: