Reputation: 3798
I have a unity container that I am registering types within like so:
IUnityContainer container = new UnityContainer()
.RegisterType<ITaxAuthorityRateService, TaxAuthorityPopulationRateService>( "PopulationRate" )
.RegisterType<ITaxAuthorityRateService, TaxAuthorityBusinessLicenseRateService>( "BusinessLicenseRate" );
Then I also want to register 2 different services that take a ITaxAuthorityRateService variable in their constructor. Both services need a different class that derives from ITaxAuthorityRateService. How can I handle that situation?
Upvotes: 1
Views: 1207
Reputation: 3798
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.
Upvotes: 9