Generics Castle Windsor开放式通用装饰器类型注册

Generics Castle Windsor开放式通用装饰器类型注册,generics,castle-windsor,castle,Generics,Castle Windsor,Castle,我试图弄清楚如何为具有2个泛型参数的泛型类型注册装饰器。下面的第一个测试用例只是一个1-generic参数用例的健全性检查,我在2-parameter用例未按预期工作时添加了该用例 第三个(失败的)1-泛型参数案例(这次是逆变型)似乎表明温莎对协变和逆变型泛型参数的处理方式不同,所以我的问题是:我在这里做错了什么 我正在使用.NET4.0 [测试] public-void RepoSingleGenericTest() { var windsorContainer=newcastle.Winds

我试图弄清楚如何为具有2个泛型参数的泛型类型注册装饰器。下面的第一个测试用例只是一个1-generic参数用例的健全性检查,我在2-parameter用例未按预期工作时添加了该用例

第三个(失败的)1-泛型参数案例(这次是逆变型)似乎表明温莎对协变和逆变型泛型参数的处理方式不同,所以我的问题是:我在这里做错了什么

我正在使用.NET4.0

[测试]
public-void RepoSingleGenericTest()
{
var windsorContainer=newcastle.Windsor.windsorContainer();
windsorContainer
.Register(所有类型的)
.FromAssembly(类型为(StringRepoSingle).Assembly)
.If(t=>typeof(CachingRepoSingle).IsAssignableFrom(t))
.WithService.FromInterface(typeof(IRepoSingle));
windsorContainer
.Register(所有类型的)
.FromAssembly(类型为(BoolRepoSingle).Assembly)
.除非(t=>typeof(CachingRepoSingle).IsAssignableFrom(t))
.WithService.FromInterface(typeof(IRepoSingle));
var stringRepo=windsorContainer.Resolve();
断言。IsInstanceOf(stringRepo);
var boolRepo=windsorContainer.Resolve();
Assert.IsInstanceOf(boolRepo);
}
[测试]
公共无效报告
{
var windsorContainer=newcastle.Windsor.windsorContainer();
windsorContainer
.寄存器(所有类型的)(类型的(IRepoDoublyGeneric))
.FromAssembly(类型为(StringRepoDoublyGeneric).Assembly)
.If(t=>typeof(CachingRepoDoublyGeneric).IsAssignableFrom(t))
.WithService.FromInterface(typeof(IRepoDoublyGeneric));
windsorContainer
.寄存器(所有类型的)(类型的(IRepoDoublyGeneric))
.FromAssembly(类型为(DateTimeRepoDoublyGeneric).Assembly)
.除非(t=>typeof(CachingRepoDoublyGeneric).IsAssignableFrom(t))
.WithService.FromInterface(typeof(IRepoDoublyGeneric));
var stringRepo=windsorContainer.Resolve();
断言。IsInstanceOf(stringRepo);
var dateTimeRepo=windsorContainer.Resolve();
Assert.IsInstanceOf(dateTimeRepo);
}
[测试]
公共无效命令测试()
{
var windsorContainer=newcastle.Windsor.windsorContainer();
windsorContainer
.寄存器(所有类型的)(类型的(ICommand))
.FromAssembly(typeof(GuidCommand).Assembly)
.If(t=>typeof(DecoratorCommand).IsAssignableFrom(t))
.WithService.FromInterface(typeof(ICommand));
windsorContainer
.寄存器(所有类型的)(类型的(ICommand))
.FromAssembly(类型(StringCommand).Assembly)
.除非(t=>typeof(DecoratorCommand).IsAssignableFrom(t))
.WithService.FromInterface(typeof(ICommand));
var stringComand=windsorContainer.Resolve();
Assert.IsInstanceOf(stringComand);
var guidCommand=windsorContainer.Resolve();
Assert.IsInstanceOf(guidCommand);
}
公共接口iReplosingle
{
TValue Get();
}
公共类StringRepoSingle:IRepoSingle
{
公共字符串Get()
{
抛出新的NotImplementedException();
}
}
公共类BoolRepoSingle:IRepoSingle
{
公共图书馆
{
抛出新的NotImplementedException();
}
}
公共类CachingRepoSingle:iReplosingle
{
私有只读iReplosingle realRepo;
公共CachingRepoSingle(IRepoSingle realRepo)
{
如果(realRepo==null)抛出新的ArgumentNullException(“realRepo”);
this.realRepo=realRepo;
}
公共部门得不到
{
抛出新的NotImplementedException();
}
}
公共接口IRepoDoublyGeneric
{
t值获取(TKey);
}
公共类stringrepooblygeneric:IRepoDoublyGeneric
{
公共字符串获取(Guid键)
{
抛出新的NotImplementedException();
}
}
公共类DateTimeRepoDoublyGeneric:IRepoDoublyGeneric
{
公共日期时间获取(Guid键)
{
抛出新的NotImplementedException();
}
}
公共类CachingRepoDoublyGeneric:IRepoDoublyGeneric
{
私有只读IRepoDoublyGeneric realRepo;
公共图书馆(IRepoDoublyGeneric realRepo)
{
如果(realRepo==null)抛出新的ArgumentNullException(“realRepo”);
this.realRepo=realRepo;
}
公共TValue Get(TKey)
{
抛出新的NotImplementedException();
}
}
公共接口ICommand
{
无效Do(T);
}
公共类StringCommand:ICommand
{
公共无效Do(字符串t)
{
抛出新的NotImplementedException();
}
}
公共类GuidCommand:ICommand
{
公共无效Do(Guid t)
{
抛出新的NotImplementedException();
}
}
公共类装饰命令:ICommand
{
私有只读ICommand realComamnd;
公共装饰社区(ICommand realComamnd)
{
如果(realComamnd==null)抛出新的ArgumentNullException(“realComamnd”);
this.realComamnd=realComamnd;
}
公共无效Do(T)
{
抛出新的NotImplementedException();
}
}
更新:下面的方法确实有效,但我不能说我认为这是最优雅的解决方案…:

[测试]
public void repodoublygeneric with reflection()
{
var windsorContainer=newcastle.Windsor.windsorContainer();
//为实现IRepoDoublyGeneric的所有类型的缓存装饰器注册组件-除了