c# - Decorating named components in windsor -
my assembly contains multiple implementations of ifoo. 1 of implementations decorator foodecorator. additionally have foofactory resolve foos decorated foodecorator. assumed best way resolve components name. current registration looks this:
component.for<ifoofactory>() .implementedby<windsorfoofactory>() .lifestylesingleton(), component.for<ifoo>() .implementedby<foodecorator>(), alltypes.fromthisassembly() .basedon<ifoo>() .configure(c => c .named(c.implementation.name))));
and implementation of factory looks this:
public class windsorfoofactory : ifoofactory { private readonly ikernel _container; public windsorfoofactory(ikernel container) { _container = container; } public ifoo newfoo(type footype) { return _container.resolve<ifoo>(footype.name); } public void returnfoo(ifoo foo) { _container.releasecomponent(foo); } }
so if assembly contains foo1, foo2 , foodecorator should have such registrations:
- component ifoo implemented foodecorator
- component ifoo implemented foo1 named foo1
- component ifoo implemented foo2 named foo2
- // component ifoo implemented foodecorator named foodecorator <-- not sure this duplicate
now factory resolving components like:
container.resolve("foo1")
and receive foo1 decorated foodecorator. there way achieve such decoration? doing wrong?
if decide use interceptor configuration should work you
container.register( component.for<foointerceptor>(), classes.fromassembly() .basedon<ifoo>() .configure(c => c.interceptors<foointerceptor>()) .configure(c => c.named(c.implementation.name)));
of course have implement foointerceptor implementing iinterceptor
you should considering replace factory typedfactory
Comments
Post a Comment