using System;
using Castle.Windsor;
using Castle.MicroKernel.Registration;
using System.Reflection;
using Castle.MicroKernel.Resolvers.SpecializedResolvers;
namespace Windsor
{
class MainClass
{
public static void Main (string[] args)
{
var container = new WindsorContainer ();
container.Register (Component.For (typeof(IIface<, >)).ImplementedBy (typeof(HandlerImpl<, >)));
//container.Register (Component.For (typeof(IIface<, >)).ImplementedBy(typeof(Impl2)));
container.Kernel.Resolver.AddSubResolver (new ArrayResolver (container.Kernel));
var normal = container.ResolveAll<IIface<Impl2, Stub>> ();
var ex = container.ResolveAll<IIface<Impl1, Stub>> ();
//var qwe = new HandlerImpl<Impl1, Stub> ();
Console.WriteLine("Hello World!");
}
}
public class Base {}
public class Stub {}
public interface AdditionalIface
{
}
public interface IIface<T1, T2> where T1 : Base where T2 : class
{
T1 Command { get; set; }
}
public class HandlerImpl<T1, T2> : IIface<T1, T2> where T1 : Base, AdditionalIface where T2 : class
{
public T1 Command { get; set; }
}
public class Impl1 : Base
{
}
public class Impl2 : Base, AdditionalIface
{
}
}
所以,现在如果我这样做:
var normal = container.ResolveAll<IIface<Impl2, Stub>> (); // this works ok
var ex = container.ResolveAll<IIface<Impl1, Stub>> (); // this throws exception abou not fullfilled constraints
// instead i want it just show no resolved implementations
有什么方法可以使这项工作如我所愿吗?
最佳答案
实际上,这似乎是 Windsor 代码中的错误。
更新:
现在已经修复
关于generics - 如何让 CaSTLe Windsor 用约束解析泛型?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3071000/