I have the following problem. I have an interface that is implemented by 2 classes. One of these classes does the real work while the other uses the first one mentioned. How can I tell the framework to use a specific implementation of an interface when instantiating a type of object? I want the controller to get the facade implementation and not the real one:
public interface IDependency
{
void Method();
}
public class Real : IDependency
{
public void Method()
{
}
}
public class Facade : IDependency
{
private IDependency dependency;
Facade(IDependency dependency) //I want a Real here
{
this.dependency=dependency;
}
public void Method()=>dependency.Method();
}
public MyController : Controller
{
private IDependency dependency;
MyController(IDependency dependency) //I want the `Facade` here not the `Real`
{
this.dependency=dependency;
}
[HttpGet]
[Route("[some route]")]
public async Task CallMethod()
{
await this.dependency.Method();
}
}
As you can see in the above example, I need a Real type of IDependency injected inside my Facade one, while I need a Facade type of IDependency injected in my MyController.
How could that be done?