@@ -69,6 +69,11 @@ public static IRegistrationBuilder<T, SimpleActivatorData, SingleRegistrationSty
6969
7070 rb . SingleInstance ( ) ;
7171
72+ // https://github.com/autofac/Autofac/issues/1102
73+ // Single instance registrations with any custom activation phases (i.e. activation handlers) need to be auto-activated,
74+ // so that other behavior (such as OnRelease) that expects 'normal' object lifetime behavior works as expected.
75+ rb . RegistrationData . AddService ( new AutoActivateService ( ) ) ;
76+
7277 rb . RegistrationData . DeferredCallback = builder . RegisterCallback ( cr =>
7378 {
7479 if ( rb . RegistrationData . Lifetime is not RootScopeLifetime ||
@@ -79,21 +84,6 @@ public static IRegistrationBuilder<T, SimpleActivatorData, SingleRegistrationSty
7984
8085 activator . DisposeInstance = rb . RegistrationData . Ownership == InstanceOwnership . OwnedByLifetimeScope ;
8186
82- // https://github.com/autofac/Autofac/issues/1102
83- // Single instance registrations with any custom activation phases (i.e. activation handlers) need to be auto-activated,
84- // so that other behavior (such as OnRelease) that expects 'normal' object lifetime behavior works as expected.
85- if ( rb . ResolvePipeline . Middleware . Any ( s => s . Phase == PipelinePhase . Activation ) )
86- {
87- var autoStartService = rb . RegistrationData . Services . First ( ) ;
88-
89- var activationRegistration = new RegistrationBuilder < T , SimpleActivatorData , SingleRegistrationStyle > (
90- new AutoActivateService ( ) ,
91- new SimpleActivatorData ( new DelegateActivator ( typeof ( T ) , ( c , p ) => c . ResolveService ( autoStartService ) ) ) ,
92- new SingleRegistrationStyle ( ) ) ;
93-
94- RegistrationBuilder . RegisterSingleComponent ( cr , activationRegistration ) ;
95- }
96-
9787 RegistrationBuilder . RegisterSingleComponent ( cr , rb ) ;
9888 } ) ;
9989
0 commit comments