Assuming the classes have the following structure for the purpose of recycling useful code:
public abstract class BaseWriter {...}
public class CommonWriter : BaseWriter {...}
public class CustomWriter : CommonWriter {...}
we have also another class that instantiates these writers, however these being initialized by dependency injection:
public class RawReports {
public CommonWriter Common {get; set;}
public CustomWriter Custom {get; set;}
}
I had a problem, injecting like below because all instances of BaseWriter were initialized with CommonWriter implementation:
services.DeclareServicesFor<CommonWriter>();
services.DeclareServicesFor<CustomWriter>();
How do i solve it and keep using dependency injection?
DeclareServicesFor
in .NET and googling doesn't return any .NET-related results. What DI library are you using? Is this your own custom method?