public void InstantiatePerScope_GetDifferentInstancesForDifferentScopes() { // This test proves that the (automatic) instantiation of the parameters of a class happens from the scope from which // the class was (manually) instantiated. This allows the developer to manually create a tenant-scoped processor which // has all its constructor parameters automatically instantiated, regardless of the level of nesting. A request / // message handling method can then be called on the tenant-scoped processor. var applicationPipeline = ApplicationPipeline.GetInstanceAndCallRegisterAndConfigure(true, null, null, false, null, Assembly.GetExecutingAssembly()); var scopedProvider1 = applicationPipeline.SP(ScopeName1); var scopedProvider2 = applicationPipeline.SP(ScopeName2); var tenantNameProvider1 = scopedProvider1.GetRequiredInstance <ITenantNameProvider>(); var tenantNameProvider2 = scopedProvider2.GetRequiredInstance <ITenantNameProvider>(); Assert.NotEqual(tenantNameProvider1, tenantNameProvider2); SimulateTenantResolution(scopedProvider1, scopedProvider2); var instance1 = scopedProvider1.GetRequiredInstance <ISomeTenantRequestProcessor>(); var instance2 = scopedProvider2.GetRequiredInstance <ISomeTenantRequestProcessor>(); Assert.NotEqual(instance1, instance2); Assert.Equal(ScopeName1, instance1.ScopeName); Assert.Equal(ScopeName2, instance2.ScopeName); Assert.NotEqual(instance1.Level1, instance2.Level1); Assert.NotEqual(instance1.Level1.Level2, instance2.Level1.Level2); instance1.HandleRequest(new object()); instance2.HandleRequest(new object()); }
public void Processing_Succeeds() { var applicationPipeline = ApplicationPipeline.GetInstanceAndCallRegisterAndConfigure(true, null, null, false, null, Assembly.GetExecutingAssembly()); VerifyDummies(applicationPipeline, false); }
public void ProcessingWithDummyAssembly_Succeeds() { var applicationPipeline = new ApplicationPipeline(x => { }, true, true, null, null, false, false, null, Assembly.GetExecutingAssembly(), x => x.AddAssemblyContainingType <global::Tests.DummyAssembly.SomeInstantiatePerScopeComponent>(), x => x.RegisterFirst(), x => x.ConfigureFirst()); VerifyDummies(applicationPipeline, true); }
public void InstantiatePerContainer_GetSameInstanceForGlobalScope() { var applicationPipeline = ApplicationPipeline.GetInstanceAndCallRegisterAndConfigure(true, null, null, false, null, Assembly.GetExecutingAssembly()); var instance1 = applicationPipeline.D.P.GetRequiredInstance <SomeInstantiatePerContainerComponent>(); var instance2 = applicationPipeline.D.P.GetRequiredInstance <SomeInstantiatePerContainerComponent>(); Assert.Equal(instance1, instance2); }
public void ProcessingWithoutDummyAssembly_Fails() { var applicationPipeline = ApplicationPipeline.GetInstanceAndCallRegisterAndConfigure(true, null, null, false, null, Assembly.GetExecutingAssembly()); VerifyDummies(applicationPipeline, false); void a() => applicationPipeline.D.P.GetRequiredInstance <global::Tests.DummyAssembly.SomeInstantiatePerScopeComponent>(); Assert.Throws <InvalidOperationException>(a); }
public void InstantiatePerScope_GetSameInstanceForGlobalScope() { var applicationPipeline = ApplicationPipeline.GetInstanceAndCallRegisterAndConfigure(true, null, null, true, null, Assembly.GetExecutingAssembly()); var instance1 = applicationPipeline.D.P.GetRequiredInstance <ISomeTenantRequestProcessor>(); var instance2 = applicationPipeline.D.P.GetRequiredInstance <ISomeTenantRequestProcessor>(); Assert.Equal(instance1, instance2); Assert.Equal("", instance1.ScopeName); Assert.Equal("", instance2.ScopeName); Assert.Equal(instance1.Level1, instance2.Level1); Assert.Equal(instance1.Level1.Level2, instance2.Level1.Level2); }
public void MultiImplementationInstance_Succeeds() { var applicationPipeline = ApplicationPipeline.GetInstanceAndCallRegisterAndConfigure(true, null, null, false, null, Assembly.GetExecutingAssembly()); var scopedProvider = applicationPipeline.SP(RightImplementationScopeName); var leftInstance = applicationPipeline.D.MI <ISomeMultiImplementation>("Left"); var rightInstance = applicationPipeline.D.MI <ISomeMultiImplementation>(scopedProvider, "Right"); Assert.Equal("Left", leftInstance.Name); Assert.Equal("Right", rightInstance.Name); Assert.Equal(leftInstance.SomeComponent, rightInstance.SomeComponent); }
public void CreateScope() { var applicationPipeline = ApplicationPipeline.GetInstanceAndCallRegisterAndConfigure(true, null, null, false, null, Assembly.GetExecutingAssembly()); Stopwatch sw = new Stopwatch(); sw.Start(); const int iterations = 7000000; IScopedInstanceProvider <string> scopedProvider; for (int i = 0; i < iterations; i++) { scopedProvider = applicationPipeline.SP(ScopeNames.Main); } Trace.WriteLine($"Speed of '{nameof( CreateScope )}' = {Speed( sw, iterations )}"); }
public void InstantiatePerScope_GetSameInstanceForSameScopeName() { var applicationPipeline = ApplicationPipeline.GetInstanceAndCallRegisterAndConfigure(true, null, null, false, null, Assembly.GetExecutingAssembly()); var scopedProvider1 = applicationPipeline.SP(ScopeName1); var scopedProvider2 = applicationPipeline.SP(ScopeName1); var tenantNameProvider1 = scopedProvider1.GetRequiredInstance <ITenantNameProvider>(); var tenantNameProvider2 = scopedProvider2.GetRequiredInstance <ITenantNameProvider>(); Assert.Equal(tenantNameProvider1, tenantNameProvider2); SimulateTenantResolution(scopedProvider1, scopedProvider2); var instance1 = scopedProvider1.GetRequiredInstance <ISomeTenantRequestProcessor>(); var instance2 = scopedProvider2.GetRequiredInstance <ISomeTenantRequestProcessor>(); Assert.Equal(instance1, instance2); Assert.Equal(ScopeName1, instance1.ScopeName); Assert.Equal(ScopeName1, instance2.ScopeName); Assert.Equal(instance1.Level1, instance2.Level1); Assert.Equal(instance1.Level1.Level2, instance2.Level1.Level2); }