本文整理汇总了C#中WindsorContainer.AddChildContainer方法的典型用法代码示例。如果您正苦于以下问题:C# WindsorContainer.AddChildContainer方法的具体用法?C# WindsorContainer.AddChildContainer怎么用?C# WindsorContainer.AddChildContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WindsorContainer
的用法示例。
在下文中一共展示了WindsorContainer.AddChildContainer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddingToTwoParentContainsThrowsKernelException
public void AddingToTwoParentContainsThrowsKernelException()
{
IWindsorContainer container3 = new WindsorContainer();
IWindsorContainer childcontainer = new WindsorContainer();
Container.AddChildContainer(childcontainer);
container3.AddChildContainer(childcontainer);
}
示例2: ShouldResolveComponentFromParent
public void ShouldResolveComponentFromParent()
{
WindsorContainer parent = new WindsorContainer();
WindsorContainer child = new WindsorContainer();
parent.AddChildContainer(child);
parent.AddComponent("DoNothingService", typeof(IDoNothingService), typeof(DoNothingService));
child.AddComponent("DoSomethingService", typeof(IDoSomethingService), typeof(DoSomethingService));
Assert.IsNotNull(child.Resolve<IDoNothingService>());
Assert.IsNotNull(child.Resolve<IDoSomethingService>());
}
示例3: ShouldResolveComponentFromParent
public void ShouldResolveComponentFromParent()
{
WindsorContainer parent = new WindsorContainer();
WindsorContainer child = new WindsorContainer();
parent.AddChildContainer(child);
((IWindsorContainer)parent).Register(Component.For(typeof(IDoNothingService)).ImplementedBy(typeof(DoNothingService)).Named("DoNothingService"));
((IWindsorContainer)child).Register(Component.For(typeof(IDoSomethingService)).ImplementedBy(typeof(DoSomethingService)).Named("DoSomethingService"));
Assert.IsNotNull(child.Resolve<IDoNothingService>());
Assert.IsNotNull(child.Resolve<IDoSomethingService>());
}
示例4: ShouldResolveComponentFromParent
public void ShouldResolveComponentFromParent()
{
var parent = new WindsorContainer();
var child = new WindsorContainer();
parent.AddChildContainer(child);
parent.Register(
Component.For<IDoNothingService>().ImplementedBy<DoNothingService>().Named("DoNothingService"),
Component.For<IDoSomethingService>().ImplementedBy<DoSomethingService>().Named("DoSomethingService"));
Assert.IsNotNull(child.Resolve<IDoNothingService>());
Assert.IsNotNull(child.Resolve<IDoSomethingService>());
}
示例5: ShouldResolveDecoratedComponentFromParent
public void ShouldResolveDecoratedComponentFromParent()
{
WindsorContainer parent = new WindsorContainer();
WindsorContainer child = new WindsorContainer();
parent.AddChildContainer(child);
parent.AddComponent("DoNothingServiceDecorator", typeof(IDoNothingService), typeof(DoNothingServiceDecorator));
parent.AddComponent("DoNothingService", typeof(IDoNothingService), typeof(DoNothingService));
child.AddComponent("DoSometingService", typeof(IDoSomethingService), typeof(DoSomethingService));
IDoNothingService service = child.Resolve<IDoNothingService>();
Assert.IsNotNull(service);
Assert.IsInstanceOf(typeof(DoNothingServiceDecorator), service);
}
示例6: Cannot_resolve_a_dependency_from_a_parent_container_under_certain_circumstances
public void Cannot_resolve_a_dependency_from_a_parent_container_under_certain_circumstances()
{
var parent = new WindsorContainer();
var child = new WindsorContainer();
parent.AddChildContainer(child);
((IWindsorContainer)parent).Register(Component.For(typeof(IParentService)).ImplementedBy(typeof(ParentService)).Named("service"));
((IWindsorContainer)child).Register(Component.For(typeof(IChildService1)).ImplementedBy(typeof(ChildService1)).Named("service1"));
((IWindsorContainer)child).Register(Component.For(typeof(IChildService2)).ImplementedBy(typeof(ChildService2)).Named("service2"));
child.Resolve<IChildService1>();
}
示例7: ShouldResolveDecoratedComponentFromGrandParent
public void ShouldResolveDecoratedComponentFromGrandParent()
{
WindsorContainer grandParent = new WindsorContainer();
WindsorContainer parent = new WindsorContainer();
WindsorContainer child = new WindsorContainer();
grandParent.AddChildContainer(parent);
parent.AddChildContainer(child);
((IWindsorContainer)grandParent).Register(Component.For(typeof(IDoNothingService)).ImplementedBy(typeof(DoNothingServiceDecorator)).Named("DoNothingServiceDecorator"));
((IWindsorContainer)grandParent).Register(Component.For(typeof(IDoNothingService)).ImplementedBy(typeof(DoNothingService)).Named("DoNothingService"));
IDoNothingService service = child.Resolve<IDoNothingService>();
Assert.IsNotNull(service);
Assert.IsInstanceOf(typeof(DoNothingServiceDecorator), service);
}
示例8: Shows_also_components_from_parent_container
public void Shows_also_components_from_parent_container()
{
var parent = new WindsorContainer();
parent.Register(Component.For<A>(),
Component.For<B>());
Container.Register(Component.For(typeof(IGeneric<>)).ImplementedBy(typeof(GenericImpl1<>)),
Component.For(typeof(IGeneric<>)).ImplementedBy(typeof(GenericImpl2<>)));
parent.AddChildContainer(Container);
var handlers = diagnostic.Inspect();
Assert.AreEqual(4, handlers.Length);
}
示例9: Should_resolve_child_from_childs_container
public void Should_resolve_child_from_childs_container()
{
WindsorContainer parent = new WindsorContainer();
WindsorContainer child = new WindsorContainer();
parent.AddChildContainer(child);
((IWindsorContainer)parent).Register(Component.For(typeof(IParentService)).ImplementedBy(typeof(ParentService)).Named("service1"));
((IWindsorContainer)parent).Register(Component.For(typeof(IChildService2)).ImplementedBy(typeof(ChildService2)).Named("service3"));
((IWindsorContainer)child).Register(Component.For(typeof(IParentService)).ImplementedBy(typeof(AnotherParentService)).Named("service2"));
IChildService2 resolve = child.Resolve<IChildService2>();
Assert.IsInstanceOf(typeof(AnotherParentService),resolve.Parent);
}
示例10: Should_resolve_child_from_childs_container
public void Should_resolve_child_from_childs_container()
{
WindsorContainer parent = new WindsorContainer();
WindsorContainer child = new WindsorContainer();
parent.AddChildContainer(child);
parent.AddComponent("service1", typeof(IParentService), typeof(ParentService));
parent.AddComponent("service3", typeof(IChildService2), typeof(ChildService2));
child.AddComponent("service2", typeof(IParentService), typeof(AnotherParentService));
IChildService2 resolve = child.Resolve<IChildService2>();
Assert.IsInstanceOf(typeof(AnotherParentService),resolve.Parent);
}
示例11: Cannot_resolve_a_dependency_from_a_parent_container_under_certain_circumstances
public void Cannot_resolve_a_dependency_from_a_parent_container_under_certain_circumstances()
{
WindsorContainer parent = new WindsorContainer();
WindsorContainer child = new WindsorContainer();
parent.AddChildContainer(child);
parent.AddComponent("service", typeof(IParentService), typeof(ParentService));
child.AddComponent("service1", typeof(IChildService1), typeof(ChildService1));
child.AddComponent("service2", typeof(IChildService2), typeof(ChildService2));
child.Resolve<IChildService1>();
}
示例12: AddComponentInstanceAndChildContainers
public void AddComponentInstanceAndChildContainers()
{
IWindsorContainer parent = new WindsorContainer();
IWindsorContainer child = new WindsorContainer();
parent.AddChildContainer(child);
IEmptyService clock1 = new EmptyServiceA();
IEmptyService clock2 = new EmptyServiceB();
parent.Kernel.Register(Component.For(typeof(IEmptyService)).Instance(clock2));
child.Kernel.Register(Component.For(typeof(IEmptyService)).Instance(clock1));
Assert.AreSame(clock2, parent.Resolve<IEmptyService>());
Assert.AreSame(clock1, child.Resolve<IEmptyService>());
}
示例13: TestForSerivces
public void TestForSerivces()
{
using (var container = new WindsorContainer())
{
container.Register(Component.For<IInterface>().ImplementedBy<InterfaceImpl>());
IInterface childInterface;
using (var childContainer = new WindsorContainer())
{
container.AddChildContainer(childContainer);
childInterface = container.Resolve<IInterface>();
} // childIhterface is NOT disposing here
var @interface = container.Resolve<IInterface>();
Assert.AreSame(@interface, childInterface);
@interface.Do();
} // but is disposing here and this is right behavior
}
示例14: AddComponentInstanceAndChildContainers
public void AddComponentInstanceAndChildContainers()
{
IWindsorContainer parent = new WindsorContainer();
IWindsorContainer child = new WindsorContainer();
parent.AddChildContainer(child);
IClock clock1 = new IsraelClock();
IClock clock2 = new WorldClock();
parent.Kernel.AddComponentInstance<IClock>(clock2);
child.Kernel.AddComponentInstance<IClock>(clock1);
Assert.AreSame(clock2,parent.Resolve<IClock>());
Assert.AreSame(clock1, child.Resolve<IClock>());
}
示例15: TestForTypedFactories
public void TestForTypedFactories()
{
using (var container = new WindsorContainer())
{
container.AddFacility<TypedFactoryFacility>();
container.Register(Component.For<IFactory>().AsFactory(),
Component.For(typeof(IInterface)).ImplementedBy(typeof(InterfaceImpl)).LifeStyle.Transient);
IFactory childFactory;
using (var childContainer = new WindsorContainer())
{
container.AddChildContainer(childContainer);
childFactory = childContainer.Resolve<IFactory>();
} // childFactory is disposing here
var factory = container.Resolve<IFactory>();
Assert.AreSame(factory, childFactory);
Assert.DoesNotThrow(() => factory.Create()); // throws an ObjectDisposedException exception
} // but should be disposed here
}