本文整理汇总了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);
}
}
}
示例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);
}
示例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>();
}
}
示例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;
}
示例5: CheckParentContOfParent
public void CheckParentContOfParent()
{
UnityContainer uc = new UnityContainer();
IUnityContainer ucchild = uc.CreateChildContainer();
object obj = uc.Parent;
Assert.IsNull(obj);
}
示例6: CheckParentContOfChild
public void CheckParentContOfChild()
{
UnityContainer uc = new UnityContainer();
IUnityContainer ucchild = uc.CreateChildContainer();
object obj = ucchild.Parent;
Assert.AreSame(uc, obj);
}
示例7: WhenResolveingAnIUnityContainerForAChildContainerItResolvesTheChildContainer
public void WhenResolveingAnIUnityContainerForAChildContainerItResolvesTheChildContainer()
{
IUnityContainer container = new UnityContainer();
IUnityContainer childContainer = container.CreateChildContainer();
IUnityContainer resolvedContainer = childContainer.Resolve<IUnityContainer>();
Assert.AreSame(childContainer, resolvedContainer);
}
示例8: ChildContainerResolvesSelf
public void ChildContainerResolvesSelf()
{
var container = new UnityContainer();
var child = container.CreateChildContainer();
var candidate = child.Resolve<IUnityContainer>();
Assert.AreSame(child, candidate);
}
示例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));
}
示例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));
}
示例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);
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}