开发者

Supply specific implementation to an interface dependency only for a specific component

开发者 https://www.devze.com 2023-04-09 15:26 出处:网络
I implemented Decorator pattern on BooCustom public class BooDefault : IBoo{} public class BooCustom : IBoo

I implemented Decorator pattern on BooCustom

public class BooDefault : IBoo{}
public class BooCustom : IBoo
{
    public BooCustom(IBoo boo)
    {
    }
}

than I have a component Foo

public class Foo : IFoo
{
    public Foo(IBoo boo)
    {
    }
}
开发者_StackOverflow社区

that depends on IBoo and only for this one I need BooCustom be the implementation for IBoo.

Any components depending on IBoo but Foo will use BooDefault including BooCustom.

Only Foo needs to have his IBoo dependency resolved by BooCustom instead of BooDefault.

How can I accomplish this resolution with windsor?

Component.For<IFoo>().ImplementedBy<Foo>()
    .Supply_BooCustom_as_Concrete_for_IBoo - Foo Dependency


Look into Handler Selectors. You should be able to create one that checks if the type requesting an IBoo is Foo. If so, it can return a specific component (in this case, the BooCustom).

0

精彩评论

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

关注公众号