I have a Mediator class with a register pipeline method that takes a message type, a pipeline filter type, and a message handler type.
internal static void RegisterPipeLine<T1, T2, T3>()
where T1 : IMessage
where T2 : BaseFilter
where T3 : IMessageHandler
{
var pipeLine = new PipeLine()
{
Filters = [typeof(T2)],
MessageHandler = typeof(T3)
};
pipeLines[typeof(T1)] = pipeLine;
}
Which I call like so
Mediator.RegisterPipeLine<Message1, LogFilter, MessageHandler1>();
This works fine, except I want to have multiple pipeline filters. So far I’ve overloaded the RegisterPipeLine method like this
internal static void RegisterPipeLine<T1, T2, T3, T4>()
where T1 : IMessage
where T2 : BaseFilter
where T3 : BaseFilter
where T4 : IMessageHandler
{
var pipeLine = new PipeLine()
{
Filters = [typeof(T2), typeof(T3)],
MessageHandler = typeof(T4)
};
pipeLines[typeof(T1)] = pipeLine;
}
Which I call like
Mediator.RegisterPipeLine<Message2, LogFilter, ValidFilter, MessageHandler2>();
But I don’t want to have to create a specific overload for every number of filters I want in the pipeline.
Is there a way to do this nicer?