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.
<PackageVersion Include="MyTrout.Pipelines" Version="4.2.0" />
                    
Directory.Packages.props
<PackageReference Include="MyTrout.Pipelines" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version 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.
#:package MyTrout.Pipelines@4.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MyTrout.Pipelines&version=4.2.0
                    
Install as a Cake Addin
#tool nuget:?package=MyTrout.Pipelines&version=4.2.0
                    
Install as a Cake Tool

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.Steps.IO.Compression

Provides Pipeline steps to zip and unzip streams.

MyTrout.Pipelines.Hosting

Provides helper classes to use a Pipeline with GenericHost.

MyTrout.Pipelines.Steps.Azure.ServiceBus

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

MyTrout.Pipelines.Steps.Cryptography

Provides Pipeline steps to encrypt, hash, and decrypt streams.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.2.0 533 11/16/2023
4.1.0 803 12/15/2022
4.0.3 2,586 12/6/2022
4.0.1 1,056 11/27/2022
4.0.0 3,684 5/5/2022
3.2.0 2,473 12/25/2021
3.1.0 948 9/27/2021
3.0.2 860 8/4/2021
3.0.1 1,734 6/28/2021
3.0.0 1,270 6/26/2021
2.1.1 873 6/3/2021
2.0.7 2,161 12/13/2020
2.0.3 1,247 11/24/2020
2.0.2 938 11/24/2020
1.1.1 954 8/29/2020
1.1.0 2,583 8/9/2020
1.0.1 1,484 7/22/2020
1.0.0 1,053 7/22/2020
0.27.0-beta 1,216 7/10/2020
0.26.3-beta 903 7/9/2020
0.26.2-beta 823 7/9/2020
0.26.1-beta 898 7/9/2020
0.26.0-beta 847 6/27/2020
0.25.0-beta 1,131 6/26/2020
0.24.0-beta 1,035 6/25/2020
0.23.0-beta 911 6/22/2020
0.22.0-beta 878 6/20/2020
0.21.0-beta 872 6/20/2020
0.20.0-beta 1,180 5/30/2020
0.19.0-beta 826 5/30/2020
0.18.0-beta 833 4/28/2020
0.16.0-beta 889 4/25/2020