0

我使用温莎城堡与IHandlerSelector多租户执行。失去多租户温莎城堡配置

我有两种形式FrmInvoice和一个自定义FrmInvoiceCustomer1共享IFrmInvoice接口。我想用我的选择器类切换它们。

public interface IFrmInvoice 
{ 
    void Show(); 
} 

container.Kernel.AddHandlerSelector(
      new FrmInvoiceSelector(
       new Type[] { typeof(IFrmInvoice) })); 

形式注册使用此代码:

container.Register(AllTypes.FromThisAssembly() 
          .Pick() 
          .If(t => t.Name.StartsWith("Frm")) 
          .Configure((c => c.LifeStyle.Transient))); 

我有我的主要形式,与此代码的按钮:

private void button1_Click(object sender, EventArgs e) 
{ 
    IFrmInvoice form1 = formsFactory.CreateForm<IFrmInvoice>(); 
    form1.Show(); 
} 

现在我要问:我如何注册IFrmInvoice接口进入温莎集装箱?这是正确的方法吗?

更新

我觉得我很接近。以这种方式它可以工作,但它注册了我的类使用的所有接口!有更好的方法吗?

container.Register(AllTypes.FromAssemblyContaining<IFrmInvoice>() 
       .BasedOn(typeof(IFrmInvoice)).WithService.AllInterfaces()); 

回答

0

确定我已经找到了解决办法:

container.Register(Component.For<IFrmInvoice>().ImplementedBy<IFrmInvoice>()); 
+0

为什么实现键入一个接口?这与原始问题有什么关系? – 2011-07-22 01:17:34

+0

“我如何注册IFrmInvoice接口”? – danyolgiax 2011-07-22 07:24:20

+0

但是你不能注册一个接口作为实现......如果可以的话,这是Windsor的一个bug。 – 2011-07-22 13:55:17

0

使用温莎安装程序执行,例如:

public class SampleInstaller : IWindsorInstaller 
{ 
    public void Install(IWindsorContainer container, IConfigurationStore store) 
    { 
     container.Kernel.AddHandlerSelector(new InvoiceHandlerSelector()); 
    } 

    public class InvoiceHandlerSelector: IHandlerSelector 
    { 
     // ... 
    } 
} 

然后再进行安装:

var container = new WindsorContainer().Install(FromAssembly.InDirectory(new AssemblyFilter(...))); 
+0

我的问题是没有注册'HandlerSelector'而是注册共享接口'IFrmInvoice'。 – danyolgiax 2011-06-16 13:29:20

0

好,现在我明白了......我们正在以这种方式注册:

public class ComponentsInstaller : IWindsorInstaller 
{ 
    public void Install(IWindsorContainer container, IConfigurationStore store) 
    { 
     var allTypesFromBinDir = AllTypes.FromAssemblyInDirectory(new AssemblyFilter(HttpRuntime.BinDirectory)); 

     container.Register(allTypesFromBinDir 
      .BasedOn<IComponentService>() 
      .WithService.FromInterface()); 
    } 
}