Tubes 2.1.0

dotnet add package Tubes --version 2.1.0
                    
NuGet\Install-Package Tubes -Version 2.1.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="Tubes" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tubes" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Tubes" />
                    
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 Tubes --version 2.1.0
                    
#r "nuget: Tubes, 2.1.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 Tubes@2.1.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=Tubes&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Tubes&version=2.1.0
                    
Install as a Cake Tool

NuGet Downloads GitHub License GitHub Issues or Pull Requests GitHub Issues or Pull Requests GitHub Repo stars GitHub watchers GitHub forks

Tubes

Tubes is a pipe and filters pattern implementation. It is based on two posts written by Steve Bate which is unfortunately no longer available.

Installation

To install Tubes, run the following command:

dotnet add package Tubes

Usage

Synchronous Pipeline

Synchronous filters must implement IFilter<TMessage> where TMessage is the type of message that will be processed through the pipeline.

The pipeline is then constructed using the Register method on the Pipeline<TMessage> class. The filters are executed in the order in which they are registered.

var loginPipeline = new Pipeline<LoginMessage>();

loginPipeline.Register(new CheckUserSuppliedCredentials())
    .Register(new ValidateAgainstMembershipApi())
    .Register(new CheckApiKeyIsEnabledForClient())
    .Register(new IsUserLoginAllowed())
    .Register(new GetUserDetails());

loginPipeline.Execute(new LoginMessage {
    Username = "User",
    Password = "Password"
});

Asynchronous Pipeline

Asynchronous filters must implement IAsyncFilter<TMessage> where TMessage is the type of message that will be processed through the pipeline.

The pipeline is then constructed using the Register method on the AsyncPipeline<TMessage> class. The filters are executed in the order in which they are registered.

var loginPipeline = new AsyncPipeline<LoginMessage>();

loginPipeline.Register(new CheckUserSuppliedCredentials())
    .Register(new CheckApiKeyIsEnabledForClient())
    .Register(new IsUserLoginAllowed())
    .Register(new ValidateAgainstMembershipApi())
    .Register(new GetUserDetails());

var cts = new CancellationTokenSource();

await loginPipeline.ExecuteAsync(new LoginMessage {
    Username = "Username",
    Password = "Password"
}, cts.Token);

IStopProcessing

If an input message implements the IStopProcessing interface, the pipeline (sync and async) will stop processing any subsequent filters if the Stop property is set to true.

The AsyncPipeline respects the CancellationToken and will stop processing any subsequent filters when cancellation is requested.

Aspects

The library also includes several aspects, viz.:

  1. Exception logging aspect
  2. Message logging aspect
  3. Retry aspect
  4. Transaction aspect

Aspects can be applied in the following manner and will be executed in the order in which they are applied:

public void Invoke(LoginMessage message)
{ 
    var logHandler = new MessageLoggingAspect<LoginMessage>(_loginPipeline.Execute) 
    var errorHandler = new ExceptionLoggingAspect<LogInMessage>(logHandler.Execute) 
    errorHandler.Execute(message);
}

Credits

Icon by ColourCreatype on freeicons.io

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.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.