I have a typed factory interface as follows:
public interface ILogMessageFactory
{
ILogMessage Create(LogMessageType logMessageType, String text);
}
and I am registering it all follows:
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.AddFacility<TypedFactoryFacility>();
container.Register(
Component.For(typeof(ConsolePrompter)),
Component.For<ILogger>().ImplementedBy<ConsoleLogger>().LifeStyle.Transient,
Component.For<ILogMessageFactory>().AsFactory(),
Component.For<ILogMessage>().ImplementedBy<LogMessage>().LifeStyle.Transient
);
}
The problem is that I want to implement the ILogMessageFactory.Create method myself, to set a few things before I return.
I’ve tried the obvious naïve solution without any success:
Component.For<ILogMessageFactory>().ImplementedBy<LogMessageFactory>().AsFactory()
Am I approaching this wrong? Should I just keep all initialization in the constructor of the given object?
use
ITypedFactoryComponentSelectorif this is something that really belongs to the factory. Alternatively use.OnCreate()on the component the factory resolves