< Summary

Information
Class: Elsa.Mediator.Middleware.Request.RequestPipelineBuilder
Assembly: Elsa.Mediator
File(s): /home/runner/work/elsa-core/elsa-core/src/common/Elsa.Mediator/Middleware/Request/RequestPipelineBuilder.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 15
Coverable lines: 15
Total lines: 51
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
get_Properties()100%210%
get_ApplicationServices()100%210%
set_ApplicationServices(...)100%210%
Use(...)100%210%
Build()0%2040%
GetProperty(...)0%620%
SetProperty(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/common/Elsa.Mediator/Middleware/Request/RequestPipelineBuilder.cs

#LineLine coverage
 1using Elsa.Mediator.Middleware.Request.Contracts;
 2
 3namespace Elsa.Mediator.Middleware.Request;
 4
 5/// <inheritdoc />
 6public class RequestPipelineBuilder : IRequestPipelineBuilder
 7{
 8    private const string ServicesKey = "mediator.Services";
 09    private readonly List<Func<RequestMiddlewareDelegate, RequestMiddlewareDelegate>> _components = new();
 10
 11    /// <summary>
 12    /// Initializes a new instance of the <see cref="RequestPipelineBuilder"/> class.
 13    /// </summary>
 014    public RequestPipelineBuilder(IServiceProvider serviceProvider)
 15    {
 016        ApplicationServices = serviceProvider;
 017    }
 18
 19    /// <inheritdoc />
 020    public IDictionary<string, object?> Properties { get; } = new Dictionary<string, object?>();
 21
 22    /// <inheritdoc />
 23    public IServiceProvider ApplicationServices
 24    {
 025        get => GetProperty<IServiceProvider>(ServicesKey)!;
 026        set => SetProperty(ServicesKey, value);
 27    }
 28
 29    /// <inheritdoc />
 30    public IRequestPipelineBuilder Use(Func<RequestMiddlewareDelegate, RequestMiddlewareDelegate> middleware)
 31    {
 032        _components.Add(middleware);
 033        return this;
 34    }
 35
 36    /// <inheritdoc />
 37    public RequestMiddlewareDelegate Build()
 38    {
 039        RequestMiddlewareDelegate pipeline = _ => new ValueTask();
 40
 041        for (int i = _components.Count - 1; i >= 0; i--)
 42        {
 043            pipeline = _components[i](pipeline);
 44        }
 45
 046        return pipeline;
 47    }
 48
 049    private T? GetProperty<T>(string key) => Properties.TryGetValue(key, out var value) ? (T?)value : default(T);
 050    private void SetProperty<T>(string key, T value) => Properties[key] = value;
 51}