-
-
Notifications
You must be signed in to change notification settings - Fork 843
AutoActivate() should not hide a component's default service
#1451
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,11 @@ public static IRegistrationBuilder<T, SimpleActivatorData, SingleRegistrationSty | |
|
|
||
| rb.SingleInstance(); | ||
|
|
||
| // 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()); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| rb.RegistrationData.DeferredCallback = builder.RegisterCallback(cr => | ||
| { | ||
| if (rb.RegistrationData.Lifetime is not RootScopeLifetime || | ||
|
|
@@ -79,21 +84,6 @@ public static IRegistrationBuilder<T, SimpleActivatorData, SingleRegistrationSty | |
|
|
||
| activator.DisposeInstance = rb.RegistrationData.Ownership == InstanceOwnership.OwnedByLifetimeScope; | ||
|
|
||
| // 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. | ||
| if (rb.ResolvePipeline.Middleware.Any(s => s.Phase == PipelinePhase.Activation)) | ||
| { | ||
| var autoStartService = rb.RegistrationData.Services.First(); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :-)) |
||
|
|
||
| var activationRegistration = new RegistrationBuilder<T, SimpleActivatorData, SingleRegistrationStyle>( | ||
| new AutoActivateService(), | ||
| new SimpleActivatorData(new DelegateActivator(typeof(T), (c, p) => c.ResolveService(autoStartService))), | ||
| new SingleRegistrationStyle()); | ||
|
|
||
| RegistrationBuilder.RegisterSingleComponent(cr, activationRegistration); | ||
| } | ||
|
|
||
| RegistrationBuilder.RegisterSingleComponent(cr, rb); | ||
| }); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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
_servicesabove so that it's clear this is not anO(N)operation.