本文整理汇总了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());
}
示例2: Setup
public void Setup()
{
parentContainer = new UnityContainer();
child1 = parentContainer.CreateChildContainer();
child2 = parentContainer.CreateChildContainer();
parentContainer.RegisterType<TestClass>(new HierarchicalLifetimeManager());
}
示例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;
}
}
示例4: Setup
public void Setup()
{
parentContainer = new UnityContainer()
.RegisterType<TestObject>(new InjectionConstructor(ValueInjectedFromParent))
.RegisterType<ILogger, MockLogger>();
childContainer = parentContainer.CreateChildContainer()
.RegisterType<TestObject>(new InjectionConstructor(ValueInjectedFromChild));
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例8: UnityHierarchicalDependencyScope
public UnityHierarchicalDependencyScope(IUnityContainer parentContainer)
{
this.container = parentContainer.CreateChildContainer();
}
示例9: PropertyInvestmentModule
public PropertyInvestmentModule(IUnityContainer container)
{
_container = container.CreateChildContainer();
}
示例10: SetupSignalrResolver
private static void SetupSignalrResolver(IUnityContainer container)
{
var signalrContainer = container.CreateChildContainer();
RegiseterSignalRServices(signalrContainer);
GlobalHost.DependencyResolver = new SignalRUnityDependencyResolver(signalrContainer);
RouteTable.Routes.MapHubs();
}
示例11: SetupMvcResolver
private static void SetupMvcResolver(IUnityContainer container)
{
var mvcContainer = container.CreateChildContainer();
RegisterMvcServices(mvcContainer);
DependencyResolver.SetResolver(new UnityDependencyResolver(mvcContainer));
}
示例12: UnityHandlerResolver
public UnityHandlerResolver(IUnityContainer container, bool createChild)
{
Container = createChild ? container.CreateChildContainer() : container;
}
示例13: InventoryModule
public InventoryModule(IUnityContainer container, IRegionManager regionManager, ILogger logger)
{
_container = container.CreateChildContainer() ;
_regionManager = regionManager;
_logger = logger;
}
示例14: ServiceScope
public ServiceScope(IUnityContainer container)
{
this.container = container.CreateChildContainer();
serviceProvider = this.container.Resolve<IServiceProvider>();
}
示例15: Plugin
public Plugin(IUnityContainer container, ILog log)
{
_log = log;
_childContainer = container.CreateChildContainer();
}