C# 迷失在多租户温莎城堡配置中
我使用Windsor Castle和C# 迷失在多租户温莎城堡配置中,c#,winforms,inversion-of-control,castle-windsor,multi-tenant,C#,Winforms,Inversion Of Control,Castle Windsor,Multi Tenant,我使用Windsor Castle和IHandlerSelector实现多租户 我有两个表单FrmInvoice和一个自定义FrmInvoiceCustomer1共享相同的IFrmInvoice界面。我想用选择器类来切换它们 public interface IFrmInvoice { void Show(); } container.Kernel.AddHandlerSelector( new FrmInvoiceSelector(
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();
}
我的主窗体上有一个带有以下代码的按钮:
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();
}
使用Windsor安装程序实现,例如:
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(...)));
好的,我找到了一个解决方案:
container.Register(Component.For<IFrmInvoice>().ImplementedBy<IFrmInvoice>());
container.Register(Component.For().ImplementedBy());
好的,现在我明白了。。我们以这种方式注册:
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());
}
}
公共类组件安装程序:IWindsorInstaller
{
public void安装(IWindsorContainer、IConfigurationStore)
{
var allTypesFromBinDir=AllTypes.fromsassemblyindirectory(新的AssemblyFilter(HttpRuntime.BinDirectory));
容器.寄存器(allTypesFromBinDir
.BasedOn()
.with.service.FromInterface());
}
}
我的问题不是注册HandlerSelector
,而是注册共享接口IFrmInvoice
。为什么实现类型是接口?这与最初的问题“我如何注册IFrmInvoice接口”有什么关系?但不能将接口注册为实现。。。如果可以的话,这是温莎的一只虫子。真的很奇怪!您可以发布一个成功使用此注册的测试吗?