当前位置: 首页>>代码示例>>C#>>正文


C# UnityContainer.CreateChildContainer方法代码示例

本文整理汇总了C#中Microsoft.Practices.Unity.UnityContainer.CreateChildContainer方法的典型用法代码示例。如果您正苦于以下问题:C# UnityContainer.CreateChildContainer方法的具体用法?C# UnityContainer.CreateChildContainer怎么用?C# UnityContainer.CreateChildContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Practices.Unity.UnityContainer的用法示例。


在下文中一共展示了UnityContainer.CreateChildContainer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        private static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                args = new[] { "10", "+", "20", "+", "30" };
            }

            using (var container = new UnityContainer())
            {
                Bootstrapper.SetupContainer(container);

                using (var childContainer = container.CreateChildContainer())
                {
                    Bootstrapper.SetupChildContainer(childContainer);

                    PerformCalculationAndWriteResult(args, childContainer);
                }

                using (var childContainer = container.CreateChildContainer())
                {
                    Bootstrapper.SetupChildContainer(childContainer);

                    PerformCalculationAndWriteResult(args, childContainer);
                }
            }
        }
开发者ID:asylzhan,项目名称:IoCTasksSolutions,代码行数:26,代码来源:Program.cs

示例2: Test

        public void Test()
        {
            var container = new UnityContainer();
            container.RegisterDatabase<MockDbContext>()
                .RegisterRepository(x => x.MockEntity1s)
                .RegisterRepository(x => x.MockEntity2s);

            var resolve1 = container.CreateChildContainer().Resolve<ResolveTree>();
            Assert.AreSame(resolve1.DbContext, resolve1.Repo1.DbContext);
            Assert.AreSame(resolve1.DbContext, resolve1.Repo2.DbContext);

            var resolve2 = container.CreateChildContainer().Resolve<ResolveTree>();
            Assert.AreNotSame(resolve1.DbContext, resolve2.DbContext);
        }
开发者ID:1and1,项目名称:Dehydrator,代码行数:14,代码来源:UnityContainerExtensionsTest.cs

示例3: CollectService

        public CollectService()
        {
            var diContainer = new UnityContainer().CreateChildContainer();
            lock (ScheduleInitLock)
            {
                var scheduler = new Quartz.Impl.StdSchedulerFactory().GetScheduler();
                if (ScheduleController == null)
                {
                    SchedulerContainer = diContainer.CreateChildContainer();
                    scheduler.JobFactory = new UnityJobFactory(SchedulerContainer);
                    ScheduleController = new ScheduleController(scheduler);
                    ScheduleController.ReschedulingAlreadyExecuted = false;
                }

                diContainer.RegisterType<IDataProvider, DataProvider>(new ContainerControlledLifetimeManager());
                diContainer.RegisterType<ICollectRequestRepository, CollectRequestRepository>(new ContainerControlledLifetimeManager());
                diContainer.RegisterType<IProbeManager, ProbeManager>();
                diContainer.RegisterType<ICollectRequestAssembler, CollectRequestAssembler>(new ContainerControlledLifetimeManager());
                diContainer.RegisterType<ICollectPackageAssembler, CollectPackageAssembler>(new ContainerControlledLifetimeManager());
                diContainer.RegisterType<ICollectResultAssembler, CollectResultAssembler>(new ContainerControlledLifetimeManager());
                diContainer.RegisterType<IDefinitionDocumentFactory, DefinitionDocumentFactory>(new ContainerControlledLifetimeManager());
                diContainer.RegisterInstance<IScheduler>(scheduler);
                diContainer.RegisterInstance<IScheduleController>(ScheduleController);

                CollectController = diContainer.Resolve<CollectController>();
            }
        }
开发者ID:JorgeHudson,项目名称:modSIC,代码行数:27,代码来源:CollectService.cs

示例4: CreateContainer

 public static IUnityContainer CreateContainer()
 {
     IUnityContainer parentContaier = new UnityContainer();
     IUnityContainer orderContainer = parentContaier.CreateChildContainer();
     UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
     section.Configure(orderContainer, "containerOne");
     return orderContainer;
 }
开发者ID:allenhan,项目名称:Green,代码行数:8,代码来源:UnityConfigurator.cs

示例5: CheckParentContOfParent

 public void CheckParentContOfParent()
 {
     UnityContainer uc = new UnityContainer();
     IUnityContainer ucchild = uc.CreateChildContainer();
     
     object obj = uc.Parent;
     
     Assert.IsNull(obj);
 }
开发者ID:CFMITL,项目名称:unity,代码行数:9,代码来源:ChildContainerInterfaceChangeFixture.cs

示例6: CheckParentContOfChild

     public void CheckParentContOfChild()
     {
         UnityContainer uc = new UnityContainer();
         IUnityContainer ucchild = uc.CreateChildContainer();
 
         object obj = ucchild.Parent;
         
         Assert.AreSame(uc, obj);
     }
开发者ID:CFMITL,项目名称:unity,代码行数:9,代码来源:ChildContainerInterfaceChangeFixture.cs

示例7: WhenResolveingAnIUnityContainerForAChildContainerItResolvesTheChildContainer

        public void WhenResolveingAnIUnityContainerForAChildContainerItResolvesTheChildContainer()
        {
            IUnityContainer container = new UnityContainer();
            IUnityContainer childContainer = container.CreateChildContainer();

            IUnityContainer resolvedContainer = childContainer.Resolve<IUnityContainer>();

            Assert.AreSame(childContainer, resolvedContainer);
        }
开发者ID:CFMITL,项目名称:unity,代码行数:9,代码来源:ContainerDefaultContentFixture.cs

示例8: ChildContainerResolvesSelf

        public void ChildContainerResolvesSelf()
        {
            var container = new UnityContainer();

            var child = container.CreateChildContainer();

            var candidate = child.Resolve<IUnityContainer>();

            Assert.AreSame(child, candidate);
        }
开发者ID:RustyF,项目名称:EnergyTrading-Core,代码行数:10,代码来源:ChildContainerFixture.cs

示例9: NamesRegisteredInParentAppearInChild

        public void NamesRegisteredInParentAppearInChild()
        {
            UnityContainer parent = new UnityContainer();
            parent.RegisterType<ITemporary, SpecialTemp>("test");
            IUnityContainer child = parent.CreateChildContainer();

            ITemporary temp = child.Resolve<ITemporary>("test");

            Assert.IsInstanceOfType(temp, typeof(SpecialTemp));
        }
开发者ID:CFMITL,项目名称:unity,代码行数:10,代码来源:ChildContainerFixture.cs

示例10: ChildInheritsParentsConfiguration_RegisterTypeResolve

        public void ChildInheritsParentsConfiguration_RegisterTypeResolve()
        {
            UnityContainer parent = new UnityContainer();
            parent.RegisterType<ITestContainer, TestContainer>(new ContainerControlledLifetimeManager());

            IUnityContainer child = parent.CreateChildContainer();
            ITestContainer objtest = child.Resolve<ITestContainer>();

            Assert.IsNotNull(objtest);
            Assert.IsInstanceOfType(objtest, typeof(TestContainer));
        }
开发者ID:CFMITL,项目名称:unity,代码行数:11,代码来源:ChildContainerInterfaceChangeFixture.cs

示例11: DisposingParentDisposesChild

        public void DisposingParentDisposesChild()
        {
            UnityContainer parent = new UnityContainer();
            IUnityContainer child = parent.CreateChildContainer();

            MyDisposableObject spy = new MyDisposableObject();
            child.RegisterInstance(spy);
            parent.Dispose();

            Assert.IsTrue(spy.WasDisposed);
        }
开发者ID:CFMITL,项目名称:unity,代码行数:11,代码来源:ChildContainerFixture.cs

示例12: CreateChildUsingParentsConfiguration

        public void CreateChildUsingParentsConfiguration()
        {
            UnityContainer parent = new UnityContainer();
            parent.RegisterType<ITemporary, Temporary>();
            IUnityContainer child = parent.CreateChildContainer();

            ITemporary temp = child.Resolve<ITemporary>();

            Assert.IsNotNull(temp);
            Assert.IsInstanceOfType(temp, typeof(Temporary));
        }
开发者ID:CFMITL,项目名称:unity,代码行数:11,代码来源:ChildContainerFixture.cs

示例13: ChildContainerResolvesInParentDefault

        public void ChildContainerResolvesInParentDefault()
        {
            var container = new UnityContainer();

            var child = container.CreateChildContainer();

            container.RegisterInstance("test", child);

            var candidate = container.Resolve<IUnityContainer>("test");

            Assert.AreSame(child, candidate);
        }
开发者ID:RustyF,项目名称:EnergyTrading-Core,代码行数:12,代码来源:ChildContainerFixture.cs

示例14: Test

        public void Test()
        {
            IUnityContainer container = new UnityContainer();
            container.RegisterType<MyObject>(new ContainerControlledLifetimeManager());

            IUnityContainer childContainer = container.CreateChildContainer();
            
            var a1 = childContainer.Resolve<MyObject>();
            var a2 = container.Resolve<MyObject>();

            Assert.AreSame(a1, a2);
        }
开发者ID:constructor-igor,项目名称:TechSugar,代码行数:12,代码来源:UnityChildLifetimeSamples.cs

示例15: OptionalParametersResolvedIfInstanceRegisteredInParentWithName

        public void OptionalParametersResolvedIfInstanceRegisteredInParentWithName()
        {
            IUnityContainer parent = new UnityContainer();
            IUnityContainer child = parent.CreateChildContainer();

            var input = new TestObject();
            parent.RegisterInstance<ITestObject>("test", input);

            NamedOptionalConstParameterClass result = child.Resolve<NamedOptionalConstParameterClass>();

            Assert.AreSame(input, result.TestObject);
        }
开发者ID:CFMITL,项目名称:unity,代码行数:12,代码来源:OptionalDependencyFixture.cs


注:本文中的Microsoft.Practices.Unity.UnityContainer.CreateChildContainer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。