Skip to content

Commit fe21ede

Browse files
committed
Multiple Simple Injector containers can now be coupled to a single service collection / service provider pair. This allows isolated SI containers per tenant in ASP.NET Core. Fixes #32
1 parent 83db1b0 commit fe21ede

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/SimpleInjector.Integration.ServiceCollection/SimpleInjectorServiceCollectionExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,10 @@ private static void AddContainerDisposalOnShutdown(
454454
// This wrapper implements disposable and allows the container to be disposed of when
455455
// IServiceProvider is disposed of. Just like Simple Injector, however, MS.DI will only
456456
// dispose of instances that are registered using this overload (not using AddSingleton<T>(T)).
457-
services.AddSingleton<ContainerDisposeWrapper>();
457+
// #32. By calling AddSingleton<T>(_ => new ...) we allow multiple wrappers to be registered, in case the
458+
// user want to couple multiple container instances to one MS.DI instance. This isn't possible when calling
459+
// AddSingleton<T>().
460+
services.AddSingleton(_ => new ContainerDisposeWrapper(options.Container));
458461

459462
options.Container.Options.ContainerLocking += (_, __) =>
460463
{

0 commit comments

Comments
 (0)