public void Dispose_DisposesTenantLifetimeScopes() { var appDependency = new StubDisposableDependency(); var tenantDependency = new StubDisposableDependency(); var builder = new ContainerBuilder(); builder.RegisterInstance(appDependency).OwnedByLifetimeScope(); var strategy = new StubTenantIdentificationStrategy() { TenantId = "tenant1" }; var mtc = new MultitenantContainer(strategy, builder.Build()); mtc.ConfigureTenant("tenant1", b => b.RegisterInstance(tenantDependency).OwnedByLifetimeScope()); // Resolve the tenant dependency so it's added to the list of things to dispose. // If you don't do this, it won't be queued for disposal and the test fails. mtc.Resolve<StubDisposableDependency>(); mtc.Dispose(); Assert.IsTrue(appDependency.IsDisposed, "The application scope didn't run Dispose."); Assert.IsTrue(tenantDependency.IsDisposed, "The tenant scope didn't run Dispose."); }