I am still getting started with Unity, and have what seems to be a simple question.
I have a class that has a dependency on two different instances of the same interface. How do I configure and resolve this class?
I.E. Given:
public interface ILogger
{
void Write(string message);
}
public class ConsoleLogger : ILogger
{
public void Write(string message)
{
Console.WriteLine(message);
}
}
public class AnotherLogger : ILogger
{
public void Write(string message)
{
Console.WriteLine(DateTime.Now.ToString() + " " + message);
}
}
public class CombinedLogger : ILogger
{
IList<ILogger> _loggers;
public CombinedLogger(params ILogger[] loggers)
{
_loggers = new List<ILogger>(loggers);
}
public void Write(string message)
{
foreach(var logger in _loggers) logger.Write(message);
}
}
I know how to configure for ConsoleLogger, and AnotherLogger. I also know how to access them in the actual code. What I seem to be blocking on is figuring out how to configure and use CombinedLogger, passing in the instances of ConsoleLogger and AnotherLogger.