BililiveRecorder/BililiveRecorder.Flv/Pipeline/ProcessingPipelineBuilder.cs
2021-03-09 00:50:13 +08:00

28 lines
934 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace BililiveRecorder.Flv.Pipeline
{
public class ProcessingPipelineBuilder : IProcessingPipelineBuilder
{
public IServiceProvider ServiceProvider { get; }
private readonly List<Func<ProcessingDelegate, ProcessingDelegate>> rules = new List<Func<ProcessingDelegate, ProcessingDelegate>>();
public ProcessingPipelineBuilder(IServiceProvider serviceProvider)
{
this.ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
}
public IProcessingPipelineBuilder Add(Func<ProcessingDelegate, ProcessingDelegate> rule)
{
this.rules.Add(rule);
return this;
}
public ProcessingDelegate Build()
=> this.rules.AsEnumerable().Reverse().Aggregate((ProcessingDelegate)(_ => { }), (i, o) => o(i));
}
}