Esempio n. 1
0
        public void UsingScope_Test_ShouldWork()
        {
            localIocManager.Register <SimpleDisposableObject>(DependencyLifeStyle.Transient);

            SimpleDisposableObject simpleObj = null;

            //scope为Action中的参数IScopedIocResolver
            localIocManager.UsingScope(scope =>
            {
                simpleObj = scope.Resolve <SimpleDisposableObject>();
            });

            simpleObj.DisposeCount.ShouldBe(1);
        }
Esempio n. 2
0
        public void UsingScope_Test_With_Constructor_ShouldWork()
        {
            localIocManager.Register <SimpleDisposableObject>(DependencyLifeStyle.Transient);

            SimpleDisposableObject simpleObj = null;

            localIocManager.UsingScope(scope =>
            {
                //使用构造函数传递参数,然后解析对象
                simpleObj = scope.Resolve <SimpleDisposableObject>(new
                {
                    myData = 40
                });
            });
            simpleObj.MyData.ShouldBe(40);
        }
Esempio n. 3
0
        public void IIocScopeResolve_Test_With_Constructor_ShouldWork()
        {
            //注册对象
            localIocManager.Register <SimpleDisposableObject>(DependencyLifeStyle.Transient);
            localIocManager.Register <SimpleDisposableObject2>(DependencyLifeStyle.Transient);
            localIocManager.Register <SimpleDisposableObject3>(DependencyLifeStyle.Transient);

            SimpleDisposableObject  simpleObj  = null;
            SimpleDisposableObject2 simpleObj2 = null;
            SimpleDisposableObject3 simpleObj3 = null;

            //在一个作用域内使用解析
            using (var scope = localIocManager.CreateScope())
            {
                simpleObj  = scope.Resolve <SimpleDisposableObject>(new { myData = 40 });
                simpleObj2 = scope.Resolve <SimpleDisposableObject2>(new { myData = 41 });
                simpleObj3 = scope.Resolve <SimpleDisposableObject3>(new { myData = 42 });
            }

            simpleObj.MyData.ShouldBe(40);
            simpleObj2.MyData.ShouldBe(41);
            simpleObj3.MyData.ShouldBe(42);
        }
Esempio n. 4
0
        public void IIocScopeResolve_Test_ShouldWork()
        {
            //注册对象
            localIocManager.Register <SimpleDisposableObject>(DependencyLifeStyle.Transient);
            localIocManager.Register <SimpleDisposableObject2>(DependencyLifeStyle.Transient);
            localIocManager.Register <SimpleDisposableObject3>(DependencyLifeStyle.Transient);

            SimpleDisposableObject  simpleObj  = null;
            SimpleDisposableObject2 simpleObj2 = null;
            SimpleDisposableObject3 simpleObj3 = null;

            //在一个作用域内使用解析
            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);
        }