Unity IOC container and how to resolve different instances of the same interface

て烟熏妆下的殇ゞ 提交于 2019-11-30 10:56:30

Ok I figured it out. Keeping the names the same during registration is correct ("PopulationRate" and "BusinessLicenseRate"). All I had to do was add an attribute to the ITaxAuthorityRateService parameter within the constructor of each service like so:

Service1 constructor parameter:

[Dependency( "BusinessLicenseRate" )]
ITaxAuthorityRateService rateService

Service2 constructor parameter:

[Dependency( "PopulationRate" )]
ITaxAuthorityRateService rateService

And then each service received the correct ITaxAuthorityRateService instance.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!