I use Windsor Castle with IHandlerSelector for multitenant implementation.
I have two forms FrmInvoice and a custom FrmInvoiceCustomer1 share same IFrmInvoice interface. I want to switch them with my selector class.
public interface IFrmInvoice
{
void Show();
}
container.Kernel.AddHandlerSelector(
new FrmInvoiceSelector(
new Type[] { typeof(IFrmInvoice) }));
Forms are registered with this code:
container.Register(AllTypes.FromThisAssembly()
.Pick()
.If(t => t.Name.StartsWith("Frm"))
.Configure((c => c.LifeStyle.Transient)));
I've my main form with a button with this code:
private void button1_Click(object sender, EventArgs e)
{
IFrmInvoice form1 = formsFactory.CreateForm<IFrmInvoice>();
form1.Show();
}
Now I ask: How I can register IFrmInvoice interface into the Windsor container? Is this the right way to do this?
update
I think I'm very close. In this way it works but it register all interfaces used by my classes! There's a better way?
container.Register(AllTypes.FromAssemblyContaining<IFrmInvoice>()
.BasedOn(typeof(IFrmInvoice)).WithService.AllInterfaces());