Exemplo n.º 1
0
        public void ScopeTest()
        {
            var builder = new XerContainerBuilder(new ContainerOptions());

            builder.RegisterTransient <ISubTransientService2, SubTestService2>();
            builder.RegisterTransient <ITransientService1, TestService1>();
            builder.RegisterTransient <ITransientService2, TestService2>();
            builder.RegisterSingleton <ISingletonService1, SingletonService1>();
            builder.RegisterTransient <ITestPropertyService, TestPropertyService>();
            var container = builder.BuildContainer();

            ITransientService1 ts11;

            using (var scope = container.BeginLifetimeScope())
            {
                ts11 = scope.Resolve <ITransientService1>();
                ITransientService1 ts12 = scope.Resolve <ITransientService1>();
                Assert.Same(ts11, ts12);
            }

            ITransientService1 ts21;

            using (var scope = container.BeginLifetimeScope())
            {
                ts21 = scope.Resolve <ITransientService1>();
                ITransientService1 ts22 = scope.Resolve <ITransientService1>();
                Assert.Same(ts21, ts22);
            }

            Assert.NotSame(ts11, ts21);
        }
Exemplo n.º 2
0
 public Controller(ITransientService1 transientService1, ITransientService2 transientService2, ITransientService3 transientService3)
 {
     TransientService1 = transientService1;
     TransientService2 = transientService2;
     TransientService3 = transientService3;
 }