I am having a 2 controller PayerController and BusinessController. Both Controller constructors takes EntityManager as a parameter which is an abstract class. I would like to resolve Each Manager class depending on the controller I am using.
For PayerController I would like to inject PayerManager class and for BusinessController I would like to inject BusinessManager.
Currentlly I am getting the last Object that has been resolved with EntityManager i.e BusinessManager.
I remember in Ninject we can do conditional injection pretty easily.
This is how current I am resolving the dependency But wont work.
Startup.cs
services.AddScoped(typeof(EntityManager), typeof(PayerManager));
services.AddScoped(typeof(EntityManager), typeof(BusinessManager));
Controllers
public class PayerController
{
private PayerManager Manager{get;}
public PayerController(EntityManager entityManager)
{
Manager = entityManager as PayerManager;
}
}
Manager Classes
public class PayerManager : EntityManager
{
public void MyPayer()
{
}
}
public class BusinessManager : EntityManager
{
public void MyBusiness()
{
}
}
public abstract class EntityManager
{
public string IAMCommon()
{
return "";
}
}