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