Exemple #1
0
        public void IIocScopedResolver_Test_IsRegistered_ShouldWork()
        {
            LocalIocManager.Register <ISimpleDependency, SimpleDependency>(DependencyLifeStyle.Transient);

            using (var scope = LocalIocManager.CreateScope())
            {
                scope.IsRegistered <ISimpleDependency>().ShouldBe(true);
                scope.IsRegistered(typeof(ISimpleDependency)).ShouldBe(true);
            }
        }
        public void IocManager_ScopeShouldWork()
        {
            Building(builder => { builder.RegisterServices(f => f.RegisterType <SimpleDisposableDependency>(Lifetime.LifetimeScope)); });

            SimpleDisposableDependency simpleDisposableDependency;

            using (IIocScopedResolver iocScopedResolver = LocalIocManager.CreateScope())
            {
                simpleDisposableDependency = iocScopedResolver.Resolve <SimpleDisposableDependency>();
            }

            simpleDisposableDependency.DisposeCount.ShouldBe(1);
        }
Exemple #3
0
        public void IIocScopedResolver_Test_Custom_Release_ShouldWork()
        {
            LocalIocManager.Register <ISimpleDependency, SimpleDependency>(DependencyLifeStyle.Transient);

            ISimpleDependency simpleDependency;

            using (var scope = LocalIocManager.CreateScope())
            {
                simpleDependency = scope.Resolve <ISimpleDependency>();
                scope.Release(simpleDependency);
            }

            simpleDependency.DisposeCount.ShouldBe(1);
        }
Exemple #4
0
        public void IIocScopedResolver_Test_ResolveAll_Should_Work_WithConstructor()
        {
            LocalIocManager.Register <ISimpleDependency, SimpleDependency>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <ISimpleDependency, SimpleDependency2>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <ISimpleDependency, SimpleDependency3>(DependencyLifeStyle.Transient);

            IEnumerable <ISimpleDependency> simpleDependendcies;

            using (var scope = LocalIocManager.CreateScope())
            {
                simpleDependendcies = scope.ResolveAll <ISimpleDependency>(new { myData = 40 });
            }

            simpleDependendcies.ShouldAllBe(x => x.MyData == 40);
        }
Exemple #5
0
        public void IIocScopedResolver_Test_ResolveAll_Should_DisposeAll_Registrants()
        {
            LocalIocManager.Register <ISimpleDependency, SimpleDependency>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <ISimpleDependency, SimpleDependency2>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <ISimpleDependency, SimpleDependency3>(DependencyLifeStyle.Transient);

            IEnumerable <ISimpleDependency> simpleDependendcies;

            using (var scope = LocalIocManager.CreateScope())
            {
                simpleDependendcies = scope.ResolveAll <ISimpleDependency>();
            }

            simpleDependendcies.ShouldAllBe(d => d.DisposeCount == 1);
        }
Exemple #6
0
        public void IIocScopedResolver_Test_ResolveAll_Should_Work_With_OtherResolvings_ConstructorArguments()
        {
            LocalIocManager.Register <ISimpleDependency, SimpleDependency>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <ISimpleDependency, SimpleDependency2>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <ISimpleDependency, SimpleDependency3>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <SimpleDisposableObject>(DependencyLifeStyle.Transient);

            IEnumerable <ISimpleDependency> simpleDependendcies;
            SimpleDisposableObject          simpleObject;

            using (var scope = LocalIocManager.CreateScope())
            {
                simpleDependendcies = scope.ResolveAll <ISimpleDependency>(new { myData = 40 });
                simpleObject        = scope.Resolve <SimpleDisposableObject>(new { myData = 40 });
            }

            simpleDependendcies.ShouldAllBe(x => x.MyData == 40);
            simpleObject.MyData.ShouldBe(40);
        }
Exemple #7
0
        public void IIocScopedResolver_Test_ResolveAll_Should_Work_With_OtherResolvings()
        {
            LocalIocManager.Register <ISimpleDependency, SimpleDependency>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <ISimpleDependency, SimpleDependency2>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <ISimpleDependency, SimpleDependency3>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <SimpleDisposableObject>(DependencyLifeStyle.Transient);

            IEnumerable <ISimpleDependency> simpleDependendcies;
            SimpleDisposableObject          simpleObject;

            using (var scope = LocalIocManager.CreateScope())
            {
                simpleDependendcies = scope.ResolveAll <ISimpleDependency>();
                simpleObject        = scope.Resolve <SimpleDisposableObject>();
            }

            simpleDependendcies.ShouldAllBe(x => x.DisposeCount == 1);
            simpleObject.DisposeCount.ShouldBe(1);
        }
Exemple #8
0
        public void IIocScopedResolver_Test_With_ConstructorArgs_ShouldWork()
        {
            LocalIocManager.Register <SimpleDisposableObject>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <SimpleDisposableObject2>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <SimpleDisposableObject3>(DependencyLifeStyle.Transient);

            SimpleDisposableObject  simpleObj;
            SimpleDisposableObject2 simpleObj2;
            SimpleDisposableObject3 simpleObj3;

            using (var scope = LocalIocManager.CreateScope())
            {
                simpleObj  = scope.Resolve <SimpleDisposableObject>(new { myData = 40 });
                simpleObj2 = scope.Resolve <SimpleDisposableObject2>(new { myData = 4040 });
                simpleObj3 = scope.Resolve <SimpleDisposableObject3>(new { myData = 404040 });
            }

            simpleObj.MyData.ShouldBe(40);
            simpleObj2.MyData.ShouldBe(4040);
            simpleObj3.MyData.ShouldBe(404040);
        }
Exemple #9
0
        public void IIocScopedResolver_Test_ShouldWork()
        {
            LocalIocManager.Register <SimpleDisposableObject>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <SimpleDisposableObject2>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <SimpleDisposableObject3>(DependencyLifeStyle.Transient);

            SimpleDisposableObject  simpleObj;
            SimpleDisposableObject2 simpleObj2;
            SimpleDisposableObject3 simpleObj3;

            using (var scope = LocalIocManager.CreateScope())
            {
                simpleObj  = scope.Resolve <SimpleDisposableObject>();
                simpleObj2 = scope.Resolve <SimpleDisposableObject2>();
                simpleObj3 = scope.Resolve <SimpleDisposableObject3>();
            }

            simpleObj.DisposeCount.ShouldBe(1);
            simpleObj2.DisposeCount.ShouldBe(1);
            simpleObj3.DisposeCount.ShouldBe(1);
        }
        public void IIocScopedResolver_Test_With_ConstructorArgs_ShouldWork()
        {
            LocalIocManager.Register <TestSimpleDisposableObject>(Key1, DependencyLifeStyle.Transient);
            LocalIocManager.Register <TestSimpleDisposableObject>(Key2, DependencyLifeStyle.Transient);
            LocalIocManager.Register <TestSimpleDisposableObject>(Key3, DependencyLifeStyle.Transient);

            TestSimpleDisposableObject testSimpleObj;
            TestSimpleDisposableObject testSimpleObj2;
            TestSimpleDisposableObject testSimpleObj3;

            using (var scope = LocalIocManager.CreateScope())
            {
                testSimpleObj  = scope.Resolve <TestSimpleDisposableObject>(Key1, new { myData = 40 });
                testSimpleObj2 = scope.Resolve <TestSimpleDisposableObject>(Key2, new { myData = 4040 });
                testSimpleObj3 = scope.Resolve <TestSimpleDisposableObject>(Key3, new { myData = 404040 });
            }

            testSimpleObj.MyData.ShouldBe(40);
            testSimpleObj2.MyData.ShouldBe(4040);
            testSimpleObj3.MyData.ShouldBe(404040);
        }
        public void IIocScopedResolver_Test_ShouldWork()
        {
            LocalIocManager.Register <TestSimpleDisposableObject>(Key1, DependencyLifeStyle.Transient);
            LocalIocManager.Register <TestSimpleDisposableObject>(Key2, DependencyLifeStyle.Transient);
            LocalIocManager.Register <TestSimpleDisposableObject>(Key3, DependencyLifeStyle.Transient);

            TestSimpleDisposableObject testSimpleObj;
            TestSimpleDisposableObject testSimpleObj2;
            TestSimpleDisposableObject testSimpleObj3;

            using (var scope = LocalIocManager.CreateScope())
            {
                testSimpleObj  = scope.Resolve <TestSimpleDisposableObject>(Key1);
                testSimpleObj2 = scope.Resolve <TestSimpleDisposableObject>(Key2);
                testSimpleObj3 = scope.Resolve <TestSimpleDisposableObject>(Key3);
            }

            testSimpleObj.DisposeCount.ShouldBe(1);
            testSimpleObj2.DisposeCount.ShouldBe(1);
            testSimpleObj3.DisposeCount.ShouldBe(1);
        }