public void BeginLifetimeScope_ChildScopeCanBeTagged() { var strategy = new StubTenantIdentificationStrategy() { TenantId = "tenant1" }; var mtc = new MultitenantContainer(strategy, new ContainerBuilder().Build()); using (var nestedScope = mtc.BeginLifetimeScope("tag")) { Assert.AreEqual("tag", nestedScope.Tag, "The child scope could not be tagged."); } }
public void BeginLifetimeScope_ChildScopeCanBeConfigured() { var strategy = new StubTenantIdentificationStrategy() { TenantId = "tenant1" }; var mtc = new MultitenantContainer(strategy, new ContainerBuilder().Build()); mtc.ConfigureTenant("tenant1", b => b.RegisterType<StubDependency1Impl1>().As<IStubDependency1>()); using (var nestedScope = mtc.BeginLifetimeScope(b => b.RegisterType<StubDependency1Impl2>().As<IStubDependency1>())) { var nestedDependency = nestedScope.Resolve<IStubDependency1>(); Assert.IsInstanceOf<StubDependency1Impl2>(nestedDependency, "The child scope was not properly configured."); } }
public void BeginLifetimeScope_CreatesLifetimeScopeForCurrentTenant() { var strategy = new StubTenantIdentificationStrategy() { TenantId = "tenant1" }; var mtc = new MultitenantContainer(strategy, new ContainerBuilder().Build()); mtc.ConfigureTenant("tenant1", b => b.RegisterType<StubDependency1Impl2>().As<IStubDependency1>().InstancePerLifetimeScope()); var tenantScope = mtc.GetCurrentTenantScope(); var tenantDependency = tenantScope.Resolve<IStubDependency1>(); using (var nestedScope = mtc.BeginLifetimeScope()) { var nestedDependency = nestedScope.Resolve<IStubDependency1>(); Assert.AreNotSame(tenantDependency, nestedDependency, "The dependency should be registered, but the scope should resolve a new instance."); } }