Tubes 2.1.0
dotnet add package Tubes --version 2.1.0
NuGet\Install-Package Tubes -Version 2.1.0
<PackageReference Include="Tubes" Version="2.1.0" />
<PackageVersion Include="Tubes" Version="2.1.0" />
<PackageReference Include="Tubes" />
paket add Tubes --version 2.1.0
#r "nuget: Tubes, 2.1.0"
#:package Tubes@2.1.0
#addin nuget:?package=Tubes&version=2.1.0
#tool nuget:?package=Tubes&version=2.1.0
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.:
- Exception logging aspect
- Message logging aspect
- Retry aspect
- 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 | Versions 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. |
-
.NETStandard 2.1
- Microsoft.Extensions.DependencyInjection (>= 9.0.4)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.