Created
May 15, 2011 05:34
-
-
Save hazzik/972902 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Domain.Tests | |
{ | |
using Castle.MicroKernel.Registration; | |
using Castle.Windsor; | |
using Xunit; | |
public class ChildContainerResolveTests | |
{ | |
public interface IService1 { } | |
public interface IService2 { } | |
public interface IService3 { } | |
public class Service1 : IService1 { } | |
public class Service1Consumer : IService2 | |
{ | |
public Service1Consumer(IService1 service1) | |
{ | |
} | |
} | |
public class Service2Consumer : IService3 | |
{ | |
public Service2Consumer(IService2 service2) | |
{ | |
} | |
} | |
[Fact] | |
public void ResolveComponentRegisteredInParentWhichDependendOnComponentRegisteredInChild() | |
{ | |
using (var parent = new WindsorContainer()) | |
using (var child = new WindsorContainer()) | |
{ | |
child.Register(Component.For<IService1>().ImplementedBy<Service1>()); | |
parent.AddChildContainer(child); | |
parent.Register(//Component.For<IService1>(), | |
Component.For<IService2>().ImplementedBy<Service1Consumer>()); | |
var consumer = child.Resolve<IService2>(); | |
Assert.NotNull(consumer); | |
} | |
} | |
[Fact] | |
public void ResolveRegisteredInChildWithDependencyOnComponentRegisteredInParentWithDependencyOnComponentRegisteredInChild() | |
{ | |
using (var parent = new WindsorContainer()) | |
using (var child = new WindsorContainer()) | |
{ | |
parent.AddChildContainer(child); | |
child.Register(Component.For<IService1>().ImplementedBy<Service1>(), | |
Component.For<IService3>().ImplementedBy<Service2Consumer>()); | |
parent.Register(//Component.For<IService1>(), | |
Component.For<IService2>().ImplementedBy<Service1Consumer>()); | |
var consumer = child.Resolve<IService3>(); | |
Assert.NotNull(consumer); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment