Esempio n. 1
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. 2
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);
        }