开发者

How do I tell Windsor to error if it can't resolve a property?

Say I have the following classes

    pu开发者_如何学编程blic 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. This part is easy, but I need a way to know if the Windsor registration for TestA is removed.

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? I do not want to use the TestB constructor, as I am looking at ways to lower constructor bloat.


If it is a mandatory dependency it should go into the constructor period. Otherwise you're allowing to instantiate an invalid component, and this has nothing to do with Windsor or 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. I'd argue that this should only be used for code that you can't control, almost never for your own code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜