예제 #1
0
        public void Singleton_Transient_RootScope()
        {
            // Arrange
            ContainerBuilder containerBuilder = new ContainerBuilder();

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

            // Assert
            secondLayer.AllInstanceNames.Should().NotEqual(secondLayer2.AllInstanceNames);
        }
예제 #2
0
        public void SinglePerScope_Singleton_TwoScope()
        {
            // Arrange
            ContainerBuilder containerBuilder = new ContainerBuilder();

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

            // Assert
            secondLayerScope1.AllInstanceNames.Should().BeEquivalentTo(secondLayerScope2.AllInstanceNames);
        }
예제 #3
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);
        }
예제 #4
0
 public ThirdLayerA(ISecondLayer secondLayer, ISecondLayerA secondLayerA)
 {
     SecondLayer  = secondLayer;
     SecondLayerA = secondLayerA;
 }
 public ThirdLayer(ISecondLayer secondLayer)
 {
     SecondLayer = secondLayer;
 }