I would like to be able to register 2 class for the same interface in my Unity container. Then, I would like to select the current implementation based on a parameter.
Here is my interface:
public interface ICheckService
{
HttpResponseMessage Validate(string p1, string p2);
}
}
My services:
public class CheckService1 : ICheckService
{
public HttpResponseMessage Validate(string p1, string p2)
{
/////code
}
}
public class CheckService2 : ICheckService
{
public HttpResponseMessage Validate(string p1, string p2)
{
////code
}
}
In the bootstraper.cs I declare my services:
`container.RegisterType<ICheckService, CheckService1>();`
`container.RegisterType<ICheckService, CheckService2>();`
My API controller:
public class ServiceController : ApiController
{
private readonly ICheckService _checkService;
public ServiceController(ICheckService checkService)
{
_checkService = checkService;
}
[HttpGet]
public HttpResponseMessage Validate(string p1, string p2)
{
return _checkService.Validate(p1, p2);
}
}
Now, I would like, when I cal my api, to select the implementation based on the p1 paramerter.
If p1 equals Service1 then the Validate method is called from Service1 class, and if p1 equals Service2, the validate method is called from Service2 class.
Thanks for your help.