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


C# IUnityContainer.CreateChildContainer方法代码示例

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


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

示例1: WhenUsingHierarchicalLifetimeWithChildContainers

 public WhenUsingHierarchicalLifetimeWithChildContainers()
 {
     parentContainer = new UnityContainer();
     child1 = parentContainer.CreateChildContainer();
     child2 = parentContainer.CreateChildContainer();
     parentContainer.RegisterType<TestClass>(new HierarchicalLifetimeManager());
 }
开发者ID:CharlesZHENG,项目名称:unity,代码行数:7,代码来源:HierarchicalLifetimeFixture.cs

示例2: Setup

 public void Setup()
 {
     parentContainer = new UnityContainer();
     child1 = parentContainer.CreateChildContainer();
     child2 = parentContainer.CreateChildContainer();
     parentContainer.RegisterType<TestClass>(new HierarchicalLifetimeManager());
 }
开发者ID:theoju,项目名称:CleanCode,代码行数:7,代码来源:HierarchicalLifetimeFixture.cs

示例3: RegisterTypes

        /// <summary>Registers the type mappings with the Unity container.</summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to 
        /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
            // container.LoadConfiguration();

            // TODO: Register your types here
            container.RegisterType<ILogger, Logger>();

            container.RegisterType<IAuthorService, AuthorServiceClient>(new InjectionConstructor());
            container.RegisterType<IBookService, BookServiceClient>(new InjectionConstructor());
            container.RegisterType<AuthorWebServiceSoap, AuthorWebServiceSoapClient>(new InjectionConstructor());
            container.RegisterType<BookWebServiceSoap, BookWebServiceSoapClient>(new InjectionConstructor());

            var _child = new ContainerWrapper(container.CreateChildContainer());

            switch (ConfigurationManager.AppSettings["service"])
            {
                case ServiceOptions.Web:
                    container.RegisterType<IAuthorServiceWrapper, WebAuthorServiceWrapper>(new InjectionConstructor(_child.Container.Resolve(typeof(AuthorWebServiceSoap))));
                    container.RegisterType<IBookServiceWrapper, WebBookServiceWrapper>(new InjectionConstructor(_child.Container.Resolve(typeof(BookWebServiceSoap))));
                    break;
                case ServiceOptions.Wcf:
                default:
                    container.RegisterType<IAuthorServiceWrapper, WcfAuthorServiceWrapper>(new InjectionConstructor(_child.Container.Resolve(typeof(IAuthorService))));
                    container.RegisterType<IBookServiceWrapper, WcfBookServiceWrapper>(new InjectionConstructor(_child.Container.Resolve(typeof(IBookService))));
                    break;
            }
        }
开发者ID:AmiraSh,项目名称:BookCatalog,代码行数:32,代码来源:UnityConfig.cs

示例4: Setup

        public void Setup()
        {
            parentContainer = new UnityContainer()
                .RegisterType<TestObject>(new InjectionConstructor(ValueInjectedFromParent))
                .RegisterType<ILogger, MockLogger>();

            childContainer = parentContainer.CreateChildContainer()
                .RegisterType<TestObject>(new InjectionConstructor(ValueInjectedFromChild));
        }
开发者ID:kangkot,项目名称:unity,代码行数:9,代码来源:BuildPlanAndChildContainerFixture.cs

示例5: Configure

        public override IUnityContainer Configure(IUnityContainer container)
        {
            IUnityContainer childContainer = container.CreateChildContainer();

            childContainer.RegisterType<IProductService, ProductService>(new ContainerControlledLifetimeManager());
            container.RegisterInstance<Func<IProductService>>(() => childContainer.Resolve<IProductService>());

            return container;
        }
开发者ID:Raconeisteron,项目名称:bakopanos,代码行数:9,代码来源:ContainerConfigurator.cs

示例6: ProcessOnBackGround

        static void ProcessOnBackGround(IUnityContainer rootContainer, string handlerName)
        {
            using (var child = rootContainer.CreateChildContainer())
            {
                // register a log with explicit name which will be task execution
                // specific
                child.RegisterInstance<ILog>(new Log(handlerName + ".txt"));

                var api = child.Resolve<ITimeAPI>();
                Console.WriteLine("{0}: Now: {1}", handlerName, api.GetNow().Result);
            }
        }
开发者ID:tobimax,项目名称:IoCTasks,代码行数:12,代码来源:Program.cs

示例7: UnityJobActivator

        public UnityJobActivator(IUnityContainer container)
        {
            _container = container.CreateChildContainer();
            //_container.RegisterType<DbModelHolder>(new PerResolveLifetimeManager());

            // _container.RegisterType<IFileSystemStorage, FileSystemStorage>(new PerResolveLifetimeManager());
            // _container.RegisterType<ITransientDependencyInjector, ThreadLocalDependencyInjector>(new PerResolveLifetimeManager());
             _container.RegisterType<IDbSessionHolder, DbSessionHolder>(new PerThreadLifetimeManager());
            try
            {
                var dbModelHolder = _container.Resolve<DbModelHolder>();
                dbModelHolder.ConnectionString = ConfigurationManager.ConnectionStrings["CommonDbContext"].ConnectionString;
            }
            catch (Exception e)
            {
                // _logger.Error("Can not create CommonDbContext container", e);
            }
        }
开发者ID:shichico,项目名称:hangfire,代码行数:18,代码来源:UnityJobActivator.cs

示例8: UnityHierarchicalDependencyScope

 public UnityHierarchicalDependencyScope(IUnityContainer parentContainer)
 {
     this.container = parentContainer.CreateChildContainer();
 }
开发者ID:calebnelton,项目名称:unity,代码行数:4,代码来源:UnityHierarchicalDependencyResolver.cs

示例9: PropertyInvestmentModule

 public PropertyInvestmentModule(IUnityContainer container)
 {
     _container = container.CreateChildContainer();
 }
开发者ID:LeeCampbell,项目名称:ArtemisWest-Mayfair,代码行数:4,代码来源:PropertyInvestmentModule.cs

示例10: SetupSignalrResolver

        private static void SetupSignalrResolver(IUnityContainer container)
        {
            var signalrContainer = container.CreateChildContainer();
            RegiseterSignalRServices(signalrContainer);

            GlobalHost.DependencyResolver = new SignalRUnityDependencyResolver(signalrContainer);
            RouteTable.Routes.MapHubs();
        }
开发者ID:EricLou,项目名称:EricLouchez,代码行数:8,代码来源:UnityConfig.cs

示例11: SetupMvcResolver

        private static void SetupMvcResolver(IUnityContainer container)
        {
            var mvcContainer = container.CreateChildContainer();
            RegisterMvcServices(mvcContainer);

            DependencyResolver.SetResolver(new UnityDependencyResolver(mvcContainer));
        }
开发者ID:EricLou,项目名称:EricLouchez,代码行数:7,代码来源:UnityConfig.cs

示例12: UnityHandlerResolver

        public UnityHandlerResolver(IUnityContainer container, bool createChild)
        {

            Container = createChild ? container.CreateChildContainer() : container;
        }
开发者ID:s-innovations,项目名称:S-Innovations.Azure.MessageProcessor,代码行数:5,代码来源:UnityHandlerResolver.cs

示例13: InventoryModule

 public InventoryModule(IUnityContainer container, IRegionManager regionManager, ILogger logger)
 {
     _container = container.CreateChildContainer() ;
     _regionManager = regionManager;
     _logger = logger;
 }
开发者ID:ssommerf,项目名称:Gateworld.Sharp,代码行数:6,代码来源:InventoryModule.cs

示例14: ServiceScope

 public ServiceScope(IUnityContainer container)
 {
     this.container = container.CreateChildContainer();
     serviceProvider = this.container.Resolve<IServiceProvider>();
 }
开发者ID:CFMITL,项目名称:unity,代码行数:5,代码来源:ServiceScope.cs

示例15: Plugin

 public Plugin(IUnityContainer container, ILog log)
 {
     _log = log;
     _childContainer = container.CreateChildContainer();
 }
开发者ID:2594636985,项目名称:BaktunShell,代码行数:5,代码来源:Plugin.cs


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