[英]How do I tell Windsor to error if it can't resolve a property?
Say I have the following classes说我有以下课程
public class TestA
{
public string Blah { get; set; }
}
public class TestB
{
public TestA Testing { get; set; }
}
So say I want Windsor to give me an instance of TestB
, but I also want it to use property injection to instantiate the TestB.Testing
property.所以说我希望 Windsor 给我一个
TestB
的实例,但我也希望它使用属性注入来实例化TestB.Testing
属性。 This part is easy, but I need a way to know if the Windsor registration for TestA
is removed.这部分很简单,但我需要一种方法来知道是否删除了
TestA
的 Windsor 注册。
Is there any way to mark the Testing
property so that Windsor knows that TestA
is a dependency of TestB
, and thus should error out if it can't resolve the Testing
property?有没有办法标记
Testing
属性,以便 Windsor 知道TestA
是TestB
的依赖项,因此如果它无法解析Testing
属性应该出错? I do not want to use the TestB
constructor, as I am looking at ways to lower constructor bloat.我不想使用
TestB
构造函数,因为我正在寻找降低构造函数膨胀的方法。
If it is a mandatory dependency it should go into the constructor period.如果它是强制依赖,它应该 go 进入构造函数期间。 Otherwise you're allowing to instantiate an invalid component, and this has nothing to do with Windsor or IoC.
否则,您将允许实例化无效组件,这与 Windsor 或 IoC 无关。
"Constructor bloat" can sometimes be a sign that the code needs to be refactored, it may have acquired too many responsibilities. “构造函数膨胀”有时可能表明代码需要重构,它可能承担了太多责任。
EDIT: if you really know what you're doing you can "manually" change dependencies as optional or mandatory using a component model contributor .编辑:如果您真的知道自己在做什么,则可以使用组件 model 贡献者“手动”将依赖项更改为可选或强制。 I'd argue that this should only be used for code that you can't control, almost never for your own code.
我认为这应该只用于您无法控制的代码,几乎从不用于您自己的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.