ok, I found a test: UseChildComponentsForParentDependenciesWhenRequestedFromChild

however this scenario is different because there is a component in parent container. Although the child component gets picked over parent component, it does not cover the scenario where parent does not have the service. So it's still a bug :)

On 2010-05-09 22:36, Neal Blomfield wrote:
Not sure what I am doing wrong here as according to IOC-56 ( which has
been applied ) the following scenario should work:

Register IServiceSix + implementation in parent container.
IServiceSix impl depends on IServiceThree.
Register IServiceThree + implementation in child container.
Resolve IServiceSix via child container.  Expected that IServiceThree
dependency is satisfied by child container, but getting a handler
exception:

Castle.MicroKernel.Handlers.HandlerException: Can't create component
'ServiceSix' as it has dependencies to be satisfied.
ServiceSix is waiting for the following dependencies:

Services:
-
Castle.Windsor.Tests.SubContainers.ChildContainerSingleResolutionTestCase
+IServiceThree which was not registered.

Relevant parts of the unit test shown below, full unit test is at
http://gist.github.com/395377.  Please note that uncommenting the
commented out line in the gist makes the test pass.

using NUnit.Framework;

namespace Castle.Windsor.Tests.SubContainers
{
     [TestFixture]
     public class ChildContainerSingleResolutionTestCase
     {
         private IWindsorContainer parentContainer;
         private IWindsorContainer childContainer;

         [SetUp]
         public void Init()
         {
             parentContainer = new WindsorContainer();
             parentContainer.AddComponent("ServiceOne",
typeof(IServiceOne), typeof(ServiceOneImpl));
             parentContainer.AddComponent("ServiceTwo",
typeof(IServiceTwo), typeof(ServiceTwoImpl));
             parentContainer.AddComponent("ServiceSix",
typeof(IServiceSix), typeof(ServiceSixImpl));

             childContainer = new WindsorContainer();
             parentContainer.AddChildContainer(childContainer);
             childContainer.AddComponent("ServiceThree",
typeof(IServiceThree), typeof(ServiceThreeImpl));
             childContainer.AddComponent("ServiceFour",
typeof(IServiceFour), typeof(ServiceFourImpl));
             childContainer.AddComponent("ServiceFive",
typeof(IServiceFive), typeof(ServiceFiveImpl));
         }

         [Test]
         public void
ResolveComplexServiceRegisteredInParentWithDependenciesRegisteredInChild()
         {
             IServiceThree serviceThree =
childContainer.Resolve<IServiceThree>(); //Proves that IServiceThree
can be resolved via child
             Assert.IsNotNull( serviceThree );
             Assert.IsInstanceOf<ServiceThreeImpl>( serviceThree );
             IServiceSix serviceSix =
childContainer.Resolve<IServiceSix>(); // This line fails =(
             Assert.IsNotNull( serviceSix );
             Assert.IsNotNull( serviceSix.GetServiceThree() );

Assert.IsInstanceOf<ServiceThreeImpl>( serviceSix.GetServiceThree() );
         }

         public interface IServiceOne { }

         public class ServiceOneImpl : IServiceOne { }

         public interface IServiceTwo
         {
             IServiceOne GetServiceOne();
         }

         public class ServiceTwoImpl : IServiceTwo
         {
             private readonly IServiceOne serviceOne;

             public ServiceTwoImpl(IServiceOne serviceOne)
             {
                 this.serviceOne = serviceOne;
             }

             public IServiceOne GetServiceOne()
             {
                 return serviceOne;
             }
         }

         public interface IServiceThree { }

         public class ServiceThreeImpl : IServiceThree { }
         public class ServiceThreeAImpl : IServiceThree { }

         public interface IServiceFour
         {
             IServiceThree GetServiceThree();
         }

         public class ServiceFourImpl : IServiceFour
         {
             private readonly IServiceThree serviceThree;

             public ServiceFourImpl(IServiceThree serviceThree)
             {
                 this.serviceThree = serviceThree;
             }

             public IServiceThree GetServiceThree()
             {
                 return serviceThree;
             }
         }

         public interface IServiceFive
         {
             IServiceOne GetServiceOne();
         }

         public class ServiceFiveImpl : IServiceFive
         {
             private readonly IServiceOne serviceOne;

             public ServiceFiveImpl(IServiceOne serviceOne)
             {
                 this.serviceOne = serviceOne;
             }

             public IServiceOne GetServiceOne()
             {
                 return serviceOne;
             }
         }

         public interface IServiceSix
         {
             IServiceThree GetServiceThree();
         }

         public class ServiceSixImpl : IServiceSix
         {
             private readonly IServiceThree serviceThree;

             public ServiceSixImpl(IServiceThree serviceThree)
             {
                 this.serviceThree = serviceThree;
             }

             public IServiceThree GetServiceThree()
             {
                 return serviceThree;
             }
         }
     }
}


--
You received this message because you are subscribed to the Google Groups "Castle 
Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to