开发者

Allow optional (null) property injection in Castle Windsor via factory method?

I've registered a component

container.Register(Component.For<XTy开发者_StackOverflowpe>()
 .LifeStyle.Is(LifestyleType.Transient)
 .UsingFactoryMethod(SomeMethod));

and am currently using this for property injection on my ASP.NET MVC controllers. However - my current problem is that SomeMethod can return null sometimes. Castle is not all too happy about this and complains about a null instance.

Is there a neat way to configure Windsor to allow this component to be null? I've been exploring the docs but haven't found a way to do it.

Thanks.


No, there's no way to pass null via Windsor.

If the component is null, than it obviously can not be used, so it would be pointless if that would be possible anyway.

If you're using this component only as a property on some other component, I think it would be better to just pass it as DynamicParameter. Windsor will then just ignore it if it's null.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜