Esempio n. 1
0
        public void Transient_Singleton_RootScope()
        {
            // Arrange
            ContainerBuilder containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType <FirstLayer>().As <IFirstLayer>().InstancePerDependency();
            containerBuilder.RegisterType <SecondLayer>().As <ISecondLayer>().SingleInstance();
            containerBuilder.RegisterType <SecondLayerA>().As <ISecondLayerA>().SingleInstance();
            IContainer container = containerBuilder.Build();
            // Act
            ISecondLayer  secondLayer   = container.Resolve <ISecondLayer>();
            ISecondLayerA secondLayerA  = container.Resolve <ISecondLayerA>();
            ISecondLayerA secondLayerA2 = container.Resolve <ISecondLayerA>();

            // Assert
            secondLayer.AllInstanceNames.Should().NotEqual(secondLayerA.AllInstanceNames);
            secondLayerA.AllInstanceNames.Should().Equal(secondLayerA2.AllInstanceNames);
        }
Esempio n. 2
0
        public void SinglePerScope_Singleton_RootScope()
        {
            // Arrange
            ContainerBuilder containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType <FirstLayer>().As <IFirstLayer>().InstancePerLifetimeScope();
            containerBuilder.RegisterType <SecondLayer>().As <ISecondLayer>().SingleInstance();
            containerBuilder.RegisterType <SecondLayerA>().As <ISecondLayerA>().SingleInstance();
            IContainer container = containerBuilder.Build();
            // Act
            ISecondLayer  secondLayer   = container.Resolve <ISecondLayer>();
            ISecondLayerA secondLayerA  = container.Resolve <ISecondLayerA>();
            ISecondLayerA secondLayerA2 = container.Resolve <ISecondLayerA>();

            // Assert
            secondLayer.FirstLayer.InstanceName.Should().Equals(secondLayerA.FirstLayer.InstanceName);
            secondLayerA.AllInstanceNames.Should().Equal(secondLayerA2.AllInstanceNames);
        }
Esempio n. 3
0
        public void Singleton_SinglePerScope_TwoScope()
        {
            // Arrange
            ContainerBuilder containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType <FirstLayer>().As <IFirstLayer>().SingleInstance();
            containerBuilder.RegisterType <SecondLayer>().As <ISecondLayer>().InstancePerLifetimeScope();
            containerBuilder.RegisterType <SecondLayerA>().As <ISecondLayerA>().InstancePerLifetimeScope();
            IContainer container = containerBuilder.Build();
            // Act
            ILifetimeScope scope1             = container.BeginLifetimeScope();
            ISecondLayer   secondLayerScope1  = scope1.Resolve <ISecondLayer>();
            ISecondLayerA  secondLayerAScope1 = scope1.Resolve <ISecondLayerA>();
            ILifetimeScope scope2             = container.BeginLifetimeScope();
            ISecondLayer   secondLayerScope2  = scope2.Resolve <ISecondLayer>();
            ISecondLayerA  secondLayerAScope2 = scope2.Resolve <ISecondLayerA>();

            // Assert
            secondLayerScope1.FirstLayer.InstanceName.Should().BeEquivalentTo(secondLayerAScope1.FirstLayer.InstanceName);
            secondLayerScope2.FirstLayer.InstanceName.Should().BeEquivalentTo(secondLayerAScope2.FirstLayer.InstanceName);
            secondLayerScope1.FirstLayer.InstanceName.Should().BeEquivalentTo(secondLayerScope2.FirstLayer.InstanceName);
            secondLayerAScope1.FirstLayer.InstanceName.Should().BeEquivalentTo(secondLayerAScope2.FirstLayer.InstanceName);
            secondLayerScope1.InstanceName.Should().NotBeEquivalentTo(secondLayerScope2.InstanceName);
        }
Esempio n. 4
0
 public ThirdLayerA(ISecondLayer secondLayer, ISecondLayerA secondLayerA)
 {
     SecondLayer  = secondLayer;
     SecondLayerA = secondLayerA;
 }