运行时城堡-温莎交换服务
假设我们将税务服务接口定义为 ItaxService,并且我们获得了多个 TaxService 实现(按地区),但是我想将特定税务实现附加到特定地区的特定客户。
DI 在这种情况下会有帮助吗? 如何? “代码片段将非常感激”
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在不了解更多的情况下,这似乎适合策略模式的实现(http://en.wikipedia .org/wiki/Strategy_pattern)。
像 Windsor 这样的依赖注入工具可以用作工厂的一种形式来确定在给定情况下使用的正确策略(税务服务)(例如,键入区域标识符),但它更让我印象深刻的是作为一种用途该工具作为对象存储库,而不是专门用于依赖项注入的目的。
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.