【发布时间】:2010-12-11 08:00:09
【问题描述】:
如何让 Windsor 尊重可选的构造函数参数以进行注入?
我尝试制作一个 IContributeComponentModelConstruction 循环遍历每个构造函数的每个 ParameterInfo 并检查它是否为 IsOptional,然后相应地在 Windsor Dependency 对象上设置 IsOptional,但这似乎没有奏效。我仍然收到“由于依赖关系......等而无法实例化”。
谢谢。
更新:
我正在使用 Silverlight 4.0 的 2.5.2.0,并且可以通过以下方式重现:
var container = new WindsorContainer();
container.Register(Component.For<TestClass>());
container.Resolve<TestClass>(); //boom
public class TestClass
{
public TestClass(ITest test=null)
{
}
}
public interface ITest
{
}
Missing dependency.
Component TestClass has a dependency on ITest, which could not be resolved.
Make sure the dependency is correctly registered in the container as a service, or provided as inline argument.
【问题讨论】:
标签: .net dependency-injection castle-windsor