MyTrout.Pipelines 4.2.0

dotnet add package MyTrout.Pipelines --version 4.2.0
NuGet\Install-Package MyTrout.Pipelines -Version 4.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MyTrout.Pipelines" Version="4.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MyTrout.Pipelines --version 4.2.0
#r "nuget: MyTrout.Pipelines, 4.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MyTrout.Pipelines as a Cake Addin
#addin nuget:?package=MyTrout.Pipelines&version=4.2.0

// Install MyTrout.Pipelines as a Cake Tool
#tool nuget:?package=MyTrout.Pipelines&version=4.2.0

Pipelines

Build Status nuget GitHub stars GitHub forks License: MIT

Quality Gate Status Coverage Maintainability Rating Security Rating Vulnerabilities

Introduction

MyTrout.Pipelines provides a non-HTTP pipeline similar to the ASP.NET Core request pipeline.

MyTrout.Pipelines targets .NET 6.0, .NET 7.0, and .NET 8.0

If three steps named M1, M2, and M3 were added to the Pipeline, here is the execution path for the code.

alternate text is missing from this package README image

The Pipeline automatically adds the NoOpStep as the last step in the Pipeline.

For more details on implementing Pipelines.Steps, see Pipelines.Steps.Core

For more details on implementing Pipelines.Hosting, see Pipelines.Hosting

Installing via NuGet

Install-Package MyTrout.Pipelines

Software dependencies

1. Microsoft.Extensions.Configuration.Abstractions 8.0.0
2. Microsoft.Extensions.Configuration.Binder 8.0.0
3. Microsoft.Extensions.DependencyInjection.Abstractions 8.0.0
4. Microsoft.Extensions.Logging.Abstractions 8.0.0

All software dependencies listed above use the MIT License.

NON-BREAKING CHANGES INTRODUCED WITH 4.0.1

See Non-breaking Changes for 4.0.1

BREAKING CHANGES INTRODUCED WITH 4.0.0

See Breaking Changes for 4.0.0

How do I use Pipelines?

PLEASE NOTE:

  • This example does not use ASP.NET Hosting or Generic Hosting to implement a pipeline.
  • For Console Applications, please use Pipelines.Hosting
  • For Pipeline Processes running within ASP.NET Core websites, there is no current recommendation.

namespace MyTrout.Pipelines.Samples.Simple
{
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Logging;
    using MyTrout.Pipelines;
    using MyTrout.Pipelines.Core;
    using System;
    using System.Threading.Tasks;
    using System.Linq;

    public class Program
    {
        static async Task Main()
        {
            // For this simple example, nothing needs to be configured, but the IConfiguration root is required.
            var config = new ConfigurationBuilder()
                            .Build();
            
            var serviceProvider = new ServiceCollection()
                                            .AddLogging();
                                            .AddTransient<IStepActivator, StepActivator>();
                                            .AddScoped<IConfiguration>(_ => config) 
                                            .Build();

            // Steps are added in the order they are executed on the request side
            // and will be executed in reverse on the response side.
            var builder = new PipelineBuilder()
                            .AddStep<M1>()
                            .AddStep<M2>()
                            .AddStep<M3>();
    
            // Build the pipeline and instantiate all steps.
            var stepActivator = serviceProvider.GetService<IStepActivator>();

            var pipeline = builder.Build(stepActivator);

            // Any name-value pairs that are required during execution would be loaded here.
            var context = new PipelineContext();
    
            // Execute the pipeline and wait for results.
            await pipeline.InvokeAsync(context).ConfigureAwait(false);

            if(context.Errors.Any())
            {
                // Throw the first exception generated by the pipeline execution.
                throw context.Errors[0];
            }
        }
    }

    public class M1 : IPipelineRequest
    {
        private readonly IPipelineRequest next;

        public M1(IPipelineRequest next) => this.next = next;

        protected virtual string Message => "I";

        public ValueTask DisposeAsync()
        {
            return new ValueTask(Task.CompletedTask);
        }

        public Task InvokeAsync(IPipelineContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.Items.ContainsKey("Message"))
            {
                context.Items["Message"] += $" {this.Message}";
            }
            else
            {
                context.Items.Add("Message", this.Message);
            }

            return this.next.InvokeAsync(context);
        }
    }

    public class M2 : M1
    {
        public M2(IPipelineRequest next) : base(next)
        {
            // no op
        }

        protected override string Message => "AM";
    }

    public class M3 : M1
    {
        public M3(IPipelineRequest next) : base(next)
        {
            // no op
        }

        protected override string Message => "HERE!";
    }
}

The previous code would execute per the text below:

  • M1 Step - All code in M1.InvokeAsync() before the call to this.next.InvokeAsync().

  • M2 Step - All code in M2.InvokeAsync() before the call to this.next.InvokeAsync().

  • M3 Step - All code in M3.InvokeAsync() before the call to this.next.InvokeAsync().

  • NoOpStep - Returns a CompletedTask to start the Response side of the Pipeline.

  • M3 Step - All code in M3.InvokeAsync() after the call to this.next.InvokeAsync().

  • M2 Step - All code in M2.InvokeAsync() after the call to this.next.InvokeAsync().

  • M1 Step - All code in M1.InvokeAsync() after the call to this.next.InvokeAsync().

The result of the execution as defined above is a string named "Message" in PipelineContext.Items with the value "I AM HERE!";

How do I write Steps?

Please refer to the Pipeline.Steps.Core for more details on how to write steps.

Build the software locally.

1. Clone the software from the Pipelines repository.
2. Build the software in Visual Studio 2019 v16.8 or higher to pull down all of the dependencies from nuget.org.
3. In Visual Studio, run all tests.  All of the should pass.
4. If you have Visual Studio Enterprise 2019, analyze the code coverage; it should be 100%.

More Documentation!

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (10)

Showing the top 5 NuGet packages that depend on MyTrout.Pipelines:

Package Downloads
MyTrout.Pipelines.Steps.IO.Files

Provides Pipeline steps to append data, read, write, delete, and move files on the file system.

MyTrout.Pipelines.Hosting

Provides helper classes to use a Pipeline with GenericHost.

MyTrout.Pipelines.Steps.IO.Compression

Provides Pipeline steps to zip and unzip streams.

MyTrout.Pipelines.Steps.Azure.ServiceBus

Provides Pipeline steps to receive and send messages to Azure Service Bus.

MyTrout.Pipelines.Steps

Provides step base classes and pipeline Stream manipulation implementations MyTrout.Pipelines.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.2.0 445 11/16/2023
4.1.0 728 12/15/2022
4.0.3 2,387 12/6/2022
4.0.1 966 11/27/2022
4.0.0 3,475 5/5/2022
3.2.0 2,281 12/25/2021
3.1.0 845 9/27/2021
3.0.2 772 8/4/2021
3.0.1 1,577 6/28/2021
3.0.0 1,177 6/26/2021
2.1.1 780 6/3/2021
2.0.7 1,981 12/13/2020
2.0.3 1,005 11/24/2020
2.0.2 833 11/24/2020
1.1.1 852 8/29/2020
1.1.0 2,367 8/9/2020
1.0.1 1,316 7/22/2020
1.0.0 945 7/22/2020
0.27.0-beta 1,055 7/10/2020
0.26.3-beta 793 7/9/2020
0.26.2-beta 724 7/9/2020
0.26.1-beta 799 7/9/2020
0.26.0-beta 732 6/27/2020
0.25.0-beta 1,006 6/26/2020
0.24.0-beta 908 6/25/2020
0.23.0-beta 808 6/22/2020
0.22.0-beta 778 6/20/2020
0.21.0-beta 771 6/20/2020
0.20.0-beta 1,010 5/30/2020
0.19.0-beta 727 5/30/2020
0.18.0-beta 727 4/28/2020
0.16.0-beta 770 4/25/2020