Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is WindsorContainers AddChildContainer really this bad?

I'm am trying to branch a number of child containers from a basic set of registrations in order to facilitate different configuration settings.

I thought based on Mark Seemanns reply on how child containers work that I could use child containers to override specific components in a base registration. However I does not seem to work as Seemann claims.

According to Mark this should work:

[TestMethod]
public void OverrideRegistrationInParentContainer()
{
    //IBusinessComponent depends on IBasicComponent
    var parentContainer = new WindsorContainer();
    parentContainer.Register(Component.For<IBasicComponent>().ImplementedBy<BasicComponent>()); //Returns 42
    parentContainer.Register(Component.For<IBusinessComponent>().ImplementedBy<RealBusinessComponent>()); //Returns the result of IBasicComponent


    var childContainer = new WindsorContainer();
    childContainer.Register(Component.For<IBasicComponent>().ImplementedBy<BasicComponent2>()); //Returns 40

    parentContainer.AddChildContainer(childContainer);

    var service = childContainer.Resolve<IBusinessComponent>();
    Assert.AreEqual(40, service.GetBusinessValue()); //This fails with the actual value being 42
}

However all dependencies are apparently resolved from the parent.

If i remove the IBasicComponent registration from the parentContainer, I am not even able to resolve the dependency due to missing registrations.

Can anyone explain how you get the container to behave as Seemann claims, or is the WindsorContainer really unable to handle this type of configuration in a graceful manner?

like image 297
Slind Avatar asked Dec 04 '25 14:12

Slind


1 Answers

The behavior you're referring to used to work in old Windsor versions but was altered in more recent versions.

Basically this is a bug, and it would allow components from child container to be visible outside its scope (when a component form parent takes a dependency on a component from child)

So the dependencies are allowed to go from child --> parent but not the other way around.

like image 176
Krzysztof Kozmic Avatar answered Dec 07 '25 15:12

Krzysztof Kozmic