简体   繁体   中英

Castle-Windsor swapping service at runtime

Let say we defined an interface for tax service as ITaxService, and we got more than one implementation of TaxService (by region) however I wanted to attach a specific tax implementation to a specific customer from the spcific region.

Will DI help in this scenario? How? "code snippet would be much appreciate"

Without knowing more, this seems like something suited to an implementation of a strategy pattern ( http://en.wikipedia.org/wiki/Strategy_pattern ).

A Dependency Injection tool like Windsor could be used as a form of factory to determine the correct strategy (tax service) to use in a given situation (say, for example, keyed on the region identifier), but it strikes me more as a use of the tool as an object repository rather than specifically for the purpose of dependency injection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM