Skip to content

Conversation

nblumhardt
Copy link
Member

Fixes #1450.

@@ -43,12 +43,15 @@ public IEnumerable<Service> Services
{
get
{
if (_defaultServiceOverridden)
if (!_defaultServiceOverridden && !_services.Contains(_defaultService))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the declared type of _services above so that it's clear this is not an O(N) operation.

@nblumhardt nblumhardt changed the title Auto activate should not hide default AutoActivate() should not hide a component's default service Mar 28, 2025
@nblumhardt
Copy link
Member Author

Not sure why AppVeyor is reporting this as non-mergeable; is that just a policy-driven thing, or is there some kind of conflict lurking? (Hoping I targeted the right branch?)

// https://github.com/autofac/Autofac/issues/1102
// Single instance registrations with any custom activation phases (i.e. activation handlers) need to be auto-activated,
// so that other behavior (such as OnRelease) that expects 'normal' object lifetime behavior works as expected.
rb.RegistrationData.AddService(new AutoActivateService());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This simplification wasn't possible prior to the other fix, as it would have broken default service logic.

// so that other behavior (such as OnRelease) that expects 'normal' object lifetime behavior works as expected.
if (rb.ResolvePipeline.Middleware.Any(s => s.Phase == PipelinePhase.Activation))
{
var autoStartService = rb.RegistrationData.Services.First();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug here is due to the possibility that there are multiple registrations for this service; resolving it won't guarantee that we end up with the same component (and in fact, some unrelated random thing could end up unexpectedly activated :-))

@tillig
Copy link
Member

tillig commented Mar 28, 2025

I'm not sure why it's saying that, but I'm on holiday until next week so I won't be able to figure it out until then. It... should just build. 🤷‍♂️

@tillig
Copy link
Member

tillig commented Apr 3, 2025

I've poked around on this trying to figure out why AppVeyor won't merge this properly and I've not found anything helpful. I'll just test it locally and call it good. I think the changes are fine. I want to move to GitHub Actions anyway, so it's not worth fighting too hard with the AppVeyor issue.

Copy link
Member

@tillig tillig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I verified the changes on my local machine rather than fighting AppVeyor. It all builds and tests out correctly. I'll see if I can get this merged and get a 0.0.1 release out the door shortly.

@tillig tillig merged commit b76e7a5 into autofac:develop Apr 3, 2025
1 check failed
@nblumhardt
Copy link
Member Author

Great - thanks! 👍

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

Successfully merging this pull request may close these issues.

AutoActivate() hides a registration's default "self" service
2 participants