mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-15 19:22:19 +08:00
37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
|
|
namespace BililiveRecorder.Flv.Pipeline
|
|
{
|
|
public class ProcessingPipelineBuilder : IProcessingPipelineBuilder
|
|
{
|
|
public IServiceCollection ServiceCollection { get; }
|
|
|
|
private readonly List<Func<ProcessingDelegate, IServiceProvider, ProcessingDelegate>> rules = new();
|
|
|
|
public ProcessingPipelineBuilder() : this(new ServiceCollection())
|
|
{ }
|
|
|
|
public ProcessingPipelineBuilder(IServiceCollection servicesCollection)
|
|
{
|
|
this.ServiceCollection = servicesCollection;
|
|
}
|
|
|
|
public IProcessingPipelineBuilder AddRule(Func<ProcessingDelegate, IServiceProvider, ProcessingDelegate> rule)
|
|
{
|
|
this.rules.Add(rule);
|
|
return this;
|
|
}
|
|
|
|
public ProcessingDelegate Build()
|
|
{
|
|
this.ServiceCollection.TryAddSingleton(_ => new ProcessingPipelineSettings());
|
|
var provider = this.ServiceCollection.BuildServiceProvider();
|
|
return this.rules.AsEnumerable().Reverse().Aggregate((ProcessingDelegate)(_ => { }), (i, o) => o(i, provider));
|
|
}
|
|
}
|
|
}
|