1
votes

I am using Castle Windsor 4.1.1. For simplicity I have created demo to illustrate the problem:

This is container initialization:

using(var container = new WindsorContainer())
{
    container.Kernel.AddHandlerSelector(new HandlerSelector());

    // Should not call handler selector
    container.Register(Component.For<IA>().ImplementedBy<AImpl>());
    container.Register(Component.For<IB>().ImplementedBy<BImpl>());

    // Should call handler selector
    container.Resolve<IA>();
}

AImpl depends on IB. (Just constructor injection)

When I call container.Register it calls HasOpinionAbout, and SelectHandler.

Question is pretty straightforward. Is it supposed to work like that?

Here is quote from official documentation:

Handler selectors let you dynamically choose a component to satisfy the requested service and override Windsor's default behavior. This is particularly useful in multi-tenant applications.

I was expecting that these functions should get called only during resolving not during registration. (They get called both during resolving and registration.)

They cleary state that it is usefull for multi-tenant applications, so in most cases tenant is determined during resolving, not during registration.

Is my assumption correct?

GitHub Issue #461

1
If those components were being registered for a multi-tenant application, one assumes they would not be registered as Singleton, as you have done here.Phil Degenhardt
@PhilDegenhardt You are correct. I missed that. Can you post it as answer?bot_insane

1 Answers

2
votes

You need to use a different lifestyle (than Singleton, which is the default) if you want to be able to have different component instances for different tenants.