Created
May 10, 2010 02:30
-
-
Save joshrobb/395599 to your computer and use it in GitHub Desktop.
This file contains 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
using NUnit.Framework; | |
using System; | |
namespace Castle.Windsor.Tests.SubContainers | |
{ | |
[TestFixture] | |
public class ChildContainerSingleResolutionTestCase | |
{ | |
private IWindsorContainer parentContainer; | |
private IWindsorContainer childContainer; | |
[SetUp] | |
public void Init() | |
{ | |
parentContainer = new WindsorContainer(); | |
parentContainer.AddComponent("ParentLogger", typeof(ILogger), typeof(ParentLogger)); | |
parentContainer.AddComponent("ServiceParentDependsLogger",typeof(ServiceParentDependsLogger)); | |
childContainer = new WindsorContainer(); | |
childContainer.AddComponent("ChildLogger", typeof(ILogger), typeof(ChildLogger)); | |
childContainer.AddComponent("ServiceChildDependsLogger",typeof(ServiceChildDependsLogger)); | |
childContainer.AddComponent("ServiceChildDependsParent",typeof(ServiceChildDependsParent)); | |
parentContainer.AddChildContainer(childContainer); | |
} | |
[Test] | |
public void DoParentChildLoggerTypesMatch() { | |
ServiceParentDependsLogger sp = parentContainer.Resolve<ServiceParentDependsLogger>(); | |
ServiceChildDependsLogger sc = childContainer.Resolve<ServiceChildDependsLogger>(); | |
ServiceChildDependsParent scdp = childContainer.Resolve<ServiceChildDependsParent>(); | |
Console.WriteLine("ServiceParentDependsLogger:" + sp.Log.GetType()); //Yes | |
Console.WriteLine("ServiceChildDependsLogger:" + sc.Log.GetType()); //Yes | |
Console.WriteLine("ServiceChildDependsParent:" + scdp.Log.GetType()); // Yes | |
Console.WriteLine("ServiceChildDependsParent:" + scdp.Parent.Log.GetType()); //Uh oh! - wtf moment in 6 months waiting to bite my ass | |
Assert.AreEqual(scdp.Log.GetType(), scdp.Parent.Log.GetType(),"Parent and Child container logger types differ"); | |
} | |
public interface ILogger {} | |
public class ParentLogger : ILogger {} | |
public class ChildLogger : ILogger {} | |
public class ServiceParentDependsLogger { | |
ILogger _log; | |
public ServiceParentDependsLogger(ILogger log) { | |
_log = log; | |
} | |
public ILogger Log { get {return _log;}} | |
} | |
public class ServiceChildDependsLogger { | |
ILogger _log; | |
public ServiceChildDependsLogger(ILogger log) { | |
_log = log; | |
} | |
public ILogger Log { get {return _log;}} | |
} | |
public class ServiceChildDependsParent { | |
ServiceParentDependsLogger _p; | |
ILogger _log; | |
public ServiceChildDependsParent(ServiceParentDependsLogger p,ILogger log) { | |
_p = p; | |
_log = log; | |
} | |
public ILogger Log { get {return _log;}} | |
public ServiceParentDependsLogger Parent { get { return _p;}} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment