Shuttle.Core.Pipelines 12.1.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package Shuttle.Core.Pipelines --version 12.1.1
NuGet\Install-Package Shuttle.Core.Pipelines -Version 12.1.1
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="Shuttle.Core.Pipelines" Version="12.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Shuttle.Core.Pipelines --version 12.1.1
#r "nuget: Shuttle.Core.Pipelines, 12.1.1"
#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 Shuttle.Core.Pipelines as a Cake Addin
#addin nuget:?package=Shuttle.Core.Pipelines&version=12.1.1

// Install Shuttle.Core.Pipelines as a Cake Tool
#tool nuget:?package=Shuttle.Core.Pipelines&version=12.1.1

Shuttle.Core.Pipelines

PM> Install-Package Shuttle.Core.Pipelines

Observable event-based pipelines based broadly on pipes and filters.

Configuration

In order to more easily make use of pipelines an implementation of the IPipelineFactory should be used. The following will register the PipelineFactory implementation:

services.AddPipelineProcessing(builder => {
    builder.AddAssembly(assembly);
});

This will register the IPipelineFactory and, using the builder, add all IPipeline and IPipelineObserver implementations as Transient. The pipeline instances are re-used as they are kept in a pool.

Since pipelines are quite frequently extended by adding observers a module may be added that adds the relevant observers to a pipeline on creation:

services.AddPipelineModule<T>();
services.AddPipelineModule(type);

The way this is accomplished is having a module such as the following:

public class SomeModule
{
    private readonly Type _pipelineType = typeof(InterestingPipeline);

    public SomeModule(IPipelineFactory pipelineFactory)
    {
        Guard.AgainstNull(pipelineFactory, nameof(pipelineFactory));

        pipelineFactory.PipelineCreated += PipelineCreated;
    }

    private void PipelineCreated(object sender, PipelineEventArgs e)
    {
        var pipelineType = ;

        if (e.Pipeline.GetType() != _pipelineType
        {
            return;
        }

        e.Pipeline.RegisterObserver(new SomeObserver());
    }
}

The above module could be added to the IServiceCollection as follows:

services.AddPipelineModule<SomeModule>();

Overview

A Pipeline is a variation of the pipes and filters pattern and consists of 1 or more stages that each contain one or more events. When the pipeline is executed each event in each stage is raised in the order that they were registered. One or more observers should be registered to handle the relevant event(s).

Each Pipeline always has its own state that is simply a name/value pair with some convenience methods to get and set/replace values. The State class will use the full type name of the object as a key should none be specified:

var state = new State();
var list = new List<string> {"item-1"};

state.Add(list); // key = System.Collections.Generic.List`1[[System.String...]]
state.Add("my-key", "my-key-value");

Console.WriteLine(state.Get<List<string>>()[0]);
Console.Write(state.Get<string>("my-key"));

Example

Events should derive from PipelineEvent.

We will use the following events:

public class OnAddCharacterA : PipelineEvent
{
}

public class OnAddCharacter : PipelineEvent
{
	public char Character { get; private set; }

	public OnAddCharacter(char character)
	{
		Character = character;
	}
}

The OnAddCharacterA event represents a very explicit event whereas with the OnAddCharacter event one can specify some data. In this case the character to add.

In order for the pipeline to process the events we will have to define one or more observers to handle the events. We will define only one for this sample but we could very easily add another that will handle one or more of the same, or other, events:

    public class CharacterPipelineObserver : 
        IPipelineObserver<OnAddCharacterA>,
        IPipelineObserver<OnAddCharacter>
    {
        public void Execute(OnAddCharacterA pipelineEvent)
        {
            var state = pipelineEvent.Pipeline.State;
            var value = state.Get<string>("value");

            value = string.Format("{0}-A", value);

            state.Replace("value", value);
        }

        public void Execute(OnAddCharacter pipelineEvent)
        {
            var state = pipelineEvent.Pipeline.State;
            var value = state.Get<string>("value");

            value = string.Format("{0}-{1}", value, pipelineEvent.Character);

            state.Replace("value", value);
        }
    }

Next we will define the pipeline itself:

var pipeline = new Pipeline();

pipeline.RegisterStage("process")
	.WithEvent<OnAddCharacterA>()
	.WithEvent(new OnAddCharacter('Z'));

pipeline.RegisterObserver(new CharacterPipelineObserver());

pipeline.State.Add("value", "start");
pipeline.Execute();

Console.WriteLine(pipeline.State.Get<string>("value")); // outputs start-A-Z

We can now execute this pipeline with predictable results.

Pipelines afford us the ability to better decouple functionality. This means that we could re-use the same observer in multiple pipelines enabling us to compose functionality at a more granular level.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Shuttle.Core.Pipelines:

Package Downloads
Shuttle.Esb The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Contains the core Shuttle.Esb assembly that should always be referenced when building Shuttle.Esb solutions.

Shuttle.Core.PipelineTransaction The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Provides a pipeline observer to handle transaction scopes.

Shuttle.Recall The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Event sourcing mechanism.

Shuttle.Core.Mediator.OpenTelemetry The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

OpenTelemetry instrumentation for Shuttle.Core.Mediator implementations.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
12.1.1 13,466 12/1/2022
12.0.0 25,963 9/4/2022
11.0.1 548 4/9/2022
11.0.0 27,631 3/21/2022
10.1.0 8,124 2/9/2021
10.0.7 17,804 11/27/2020
10.0.6 87,407 7/4/2018
10.0.5 984 4/12/2018
10.0.4 1,702 4/8/2018
10.0.3 906 4/7/2018
10.0.2 14,091 2/13/2018