I have the child-parent class relationship but I don’t have any startup class to resolve the dependency explicitly. In addition, I don't want to remove empty constructor from child class as it has a dependency. How and Where can I configure my containers to achieve dependency injection implementation?
Currently, I am achieving it using below logic for unit testing mocking purpose.
Is it possible to dynamically resolve dependency using MEF C# or through base lass. Any help appreciated.
e.g.
public class child : Parent
{
private ILogger _logger;
public child() : this(new FileLogger()) { }
public child(ILogger logger)
{
_logger = logger;
}
public void DoWork()
{
//Perform Work.
_logger.Log("Log Work Here");
}
}
public abstract class Parent
{
//Common Operations
}
public interface ILogger
{
void Log(string message);
}
//Multiple Inplementation for ILogger
public class FileLogger : ILogger
{
public void Log(string message)
{
//Log into file.
}
}