我正在尝试使用 Windsor 作为工厂来提供基于 XAbstractBase
子类型的规范实现。 (在我的例子中是一个抽象消息基类)。
我有如下代码:
public abstract class XAbstractBase { }
public class YImplementation : XAbstractBase { }
public class ZImplementation : XAbstractBase { }
public interface ISpecification<T> where T : XAbstractBase
{
bool PredicateLogic();
}
public class DefaultSpecificationImplementation : ISpecification<XAbstractBase>
{
public bool PredicateLogic() { return true; }
}
public class SpecificSpecificationImplementation : ISpecification<YImplementation>
{
public bool PredicateLogic() { /*do real work*/ }
}
我的组件注册码是这样的:
container.Register(
AllTypes.FromAssembly(Assembly.GetExecutingAssembly())
.BasedOn(typeof(ISpecification<>))
.WithService.FirstInterface()
)
当我尝试解析 ISpecification<YImplementation>
时,这工作正常;它正确地解析了 SpecificSpecificationImplementation
.
但是,当我尝试解析 ISpecification<ZImplementation>
温莎抛出异常:
"No component for supporting the service ISpecification'1[ZImplementation, AssemblyInfo...] was found"
如果没有注册更具体的实现,Windsor 是否支持将通用实现分解为基类?
最佳答案
关于c# - CaSTLe Windsor - 将泛型实现解析为基类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3039296/