For several weeks, I used the Simple Injector container with great success . I like it easily with which I can customize it. But now I have a design that I don’t know how to customize. I have a base class in which many types are inferred, and I want to attach a dependency to a property of the base class, but without the need to configure this for each derived class. I tried to do this using attributes, but Simple Injector does not support attributes. Here is a stripped down version of my design.
public interface Handler<TMessage> where TMessage : Message
{
void Handle(TMessage message);
}
public abstract class BaseHandler
{
public HandlerContext Context { get; set; }
}
public class NotifyCustomerHandler : BaseHandler,
Handler<NotifyCustomerMessage>
{
public NotifyCustomerHandler(SomeDependency dependency)
{
}
public void Handle(NotifyCustomerMessage message)
{
}
}
Now my configuration is as follows:
container.Register<HandlerContext, AspHandlerContext>();
container.Register<Handler<NotifyCustomerMessage>, NotifyCustomerHandler>();
How can I insert a property in a BaseHandler?
Thanks in advance for your help.