I have designed a telemetry logger for few separate platforms using the component pattern
public interface ILogger
{
void Log();
}
public class A : ILogger
{
public void Log(...);
}
public class B : ILogger
{
public void Log(...);
}
public class Many : ILogger
{
private readonly List<ILogger> m_loggers;
public Many(IEnumerable<ILogger> loggers)
{
m_loggers = loggers.ToList();
}
public void Log()
{
m_loggers.ForEach(c => c.Log());
}
}
Now i want to be able to get an instance of "Many" from Windsor container but have encountered a few problems:
-
if all ILoggers are in the container how can i make sure i get the "Many" implementation and not "A" or "B" ?
-
I tried following this example Castle Windsor: How do I inject all implementations of interface into a ctor? and use
container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel));
to register a class with IEnumerable dependancy but if that class also implements IComponent wont it create a circular dependency ?
Is what i'm attempting even possible ?
Aucun commentaire:
Enregistrer un commentaire