PipelineNet icon indicating copy to clipboard operation
PipelineNet copied to clipboard

implement AddBefore and AddAfter Methods

Open furesoft opened this issue 6 years ago • 1 comments

this is good for an extensible pipeline through plugins

furesoft avatar Oct 13 '19 16:10 furesoft

If this is specific to plugins and anybody wants this maybe they could inherit:

public class PluginPipeline<TParameter> : Pipeline<TParameter>
{
    public PluginPipeline(IMiddlewareResolver middlewareResolver) : base(middlewareResolver)
    {
    }

    public void AddBefore<TMiddleware1, TMiddleware2>()
        where TMiddleware1 : IMiddleware<TParameter>
        where TMiddleware2 : IMiddleware<TParameter>
    {
        int index = MiddlewareTypes.IndexOf(typeof(TMiddleware1)); // Insert before first occurrence only.
        if (index == -1)
        {
            throw new InvalidOperationException($"No occurence of '{typeof(TMiddleware1)}' found.");
        }
        MiddlewareTypes.Insert(index, typeof(TMiddleware2));
    }
}

?

Would actually be nice if someone made a pull request and made all public methods on Pipeline<TParameter> / AsyncPipeline<TParameter> / ResponsibilityChain<TParameter, TReturn> / AsyncResponsibilityChain<TParameter, TReturn> virtual.

mariusz96 avatar Nov 11 '24 11:11 mariusz96