Tx.Core.Pipeline
1.1.0
dotnet add package Tx.Core.Pipeline --version 1.1.0
NuGet\Install-Package Tx.Core.Pipeline -Version 1.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="Tx.Core.Pipeline" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tx.Core.Pipeline --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Tx.Core.Pipeline, 1.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.
// Install Tx.Core.Pipeline as a Cake Addin #addin nuget:?package=Tx.Core.Pipeline&version=1.1.0 // Install Tx.Core.Pipeline as a Cake Tool #tool nuget:?package=Tx.Core.Pipeline&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Thanks to JEREMY DAVIS for this articule: https://jermdavis.wordpress.com/2016/10/03/an-alternative-approach-to-pipelines/
Exmaple:
- Define some steps
public class DoNothingStep : IAsyncPipelineStep<int, int>
{
public string StepName => $"{GetType().Name}";
public Task<int> ProcessAsync(int input) => Task.FromResult(input);
}
public class Step1: IAsyncPipelineStep<int, int>
{
public string StepName => "Step one";
public Task<int> ProcessAsync(int input)
{
Console.WriteLine($"Processing {StepName}");
++input;
return Task.FromResult(input);
}
}
public class Step2: IAsyncPipelineStep<int, int>
{
public string StepName => "Step two";
public Task<int> ProcessAsync(int input)
{
Console.WriteLine($"Processing {StepName}");
--input;
return Task.FromResult(input);
}
}
- Define one or more Pipelines, you can exchange the steps
public class DemoPipeline : AsyncPipeline<int, int>
{
public DemoPipeline(
Step1 step1,
Step2 step2,
DoNothingStep doNothingStep)
{
PipelineSteps = input => input
.Step(step1)
.Step(Step2)
}
}
public class ConditionalDemoPipeline : AsyncPipeline<int, int>
{
public ConditionalDemoPipeline(
Step1 step1,
Step2 step2,
DoNothingStep doNothingStep)
{
PipelineSteps = input => input
.Step(step1)
.When(() => input > 0, step2, doNothingStep)
}
}
- Register multiple instance in the Container
// Register Pipelines Steps
services.AddSingleton(sp => ActivatorUtilities.CreateInstance<DoNothingStep>(sp));
services.AddSingleton(sp => ActivatorUtilities.CreateInstance<Step1>(sp));
services.AddSingleton(sp => ActivatorUtilities.CreateInstance<Step2>(sp));
// Register Pipelines
services.AddSingleton(sp => ActivatorUtilities.CreateInstance<ConditionalDemoPipeline>(sp));
services.AddSingleton(sp => ActivatorUtilities.CreateInstance<DemoPipeline>(sp));
- Use the Pipeline in your class
public class PipelineProcessor
{
private readonly ConditionalDemoPipeline _pipeline;
public PipelineProcessor(ConditionalDemoPipeline pipeline)
{
_pipeline = pipeline;
}
public async Task Handle(CancellationToken cancellationToken)
{
var result = await _pipeline.ProcessAsync(5);
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Upgrate to net 8.0