c# - Proper way of injecting different set of componenets based on some flag in Windsor -
i working legacy application. in spear time, want make clean components initialization , move of them windsor (which our company di framework of choice).
unfortunately, in old days, 1 decided use windsor via xml configuration files, complicating things...
ok, straight problem. want inject different set of implementation depending on flag or root component implementation, example, let's have flowa , flowb , want have hierarchy injected:
flowa:
- somefactorya : ifactorycomponenet
- someservice1a : iservice1
- someservice2 : iservice2
- someservice3 : iservice3
flowb:
- somefactoryb : ifactorycomponenet
- someservice1b : iservice1
- someservice2 : iservice2
- someservice3 : iservice3
basically, of components have single implementation, have different. have few implementations of services, legacy mode, new flow, other special variants of flow.
the thing came mind wrap staff in factory, have feeling removing di framework in way , loosing flexibility of individual components changes.
is there way instruct windsor recognize parameter , inject different implementations? or misusing di here. if latter, suggestions how deal kind of requirements apart , old school switch (eventually hidden behind factory)
thanks, mike
you may check named dependencies
you can try like
flowa , flowb implement iworkflow
container.register(component.for<iworkflow>().implementedby<flowa>() .dependson(serviceoverride.forkey<iservice1>().eq("someservice1a"))); container.register(component.for<iservice1>().implementedby<someservice1a>() .named("someservice1a"));
with enforce specific dependency someservice1a flowa. same workflow specific dependencies (eg. ifactorycomponenet)
Comments
Post a Comment