@@ -22,9 +22,9 @@ namespace SimpleInjector
2222 /// </summary>
2323 public static class SimpleInjectorServiceCollectionExtensions
2424 {
25- private static readonly object AddOptionsKey = new object ( ) ;
26- private static readonly object AddLoggingKey = new object ( ) ;
27- private static readonly object AddLocalizationKey = new object ( ) ;
25+ private static readonly object AddOptionsKey = new ( ) ;
26+ private static readonly object AddLoggingKey = new ( ) ;
27+ private static readonly object AddLocalizationKey = new ( ) ;
2828
2929 /// <summary>
3030 /// Sets up the basic configuration that allows Simple Injector to be used in frameworks that require
@@ -457,17 +457,20 @@ private static void AddContainerDisposalOnShutdown(
457457 // #32. By calling AddSingleton<T>(_ => new ...) we allow multiple wrappers to be registered, in case the
458458 // user want to couple multiple container instances to one MS.DI instance. This isn't possible when calling
459459 // AddSingleton<T>().
460- services . AddSingleton ( _ => new ContainerDisposeWrapper ( options . Container ) ) ;
460+ var wrapper = new ContainerDisposeWrapper ( options . Container ) ;
461+ services . AddSingleton ( _ => wrapper ) ;
461462
462463 options . Container . Options . ContainerLocking += ( _ , __ ) =>
463464 {
464465 // If there's no IServiceProvider, the property will throw, which is something we want to do
465466 // at this point, not later on, when an unregistered type is resolved.
466467 IServiceProvider provider = options . ApplicationServices ;
467468
468- // In order for the wrapper to get disposed of, it needs to be resolved once.
469- var wrapper = provider . GetRequiredService < ContainerDisposeWrapper > ( ) ;
470- wrapper . FrameworkProviderType = provider . GetType ( ) ;
469+ // In order for the wrappers to get disposed of, they needs to be resolved once.
470+ foreach ( var wrapper in provider . GetServices < ContainerDisposeWrapper > ( ) )
471+ {
472+ wrapper . FrameworkProviderType = provider . GetType ( ) ;
473+ }
471474 } ;
472475 }
473476
0 commit comments