Reputation: 3377
In my Windows Phone 8 app I have multiple services which implements the same interface. Based on user selection I need to use one of these services (implementations).
Usually I configure my services in bootstrapper, like this:
protected override void Configure()
{
...
container.PerRequest<ICarService, CompanyACarService>();
//container.PerRequest<ICarService, CompanyBCarService>();
...
}
How should I add functionality to bootstrapper, so that It chooses CompanyACarService or CompanyBCarService implementation based on some logic?
Upvotes: 0
Views: 959
Reputation: 16361
You can use
container.RegisterPerRequest(interface, key, implementation);
to register multiple implementations of an interface with different keys (identifiers). Then you can use the service locator (anti)pattern to get an instance
var instance = IoC.Get<interface>(key);
I do not think you can achieve the same result using constructor injection
Upvotes: 1