LittlePipeline 3.0.0

dotnet add package LittlePipeline --version 3.0.0                
NuGet\Install-Package LittlePipeline -Version 3.0.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="LittlePipeline" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LittlePipeline --version 3.0.0                
#r "nuget: LittlePipeline, 3.0.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 LittlePipeline as a Cake Addin
#addin nuget:?package=LittlePipeline&version=3.0.0

// Install LittlePipeline as a Cake Tool
#tool nuget:?package=LittlePipeline&version=3.0.0                

LittlePipeline

Build Status NuGet Downloads

What is it?

A pipeline, process, or whatever is a sequence of actions that need to be performed to complete an operation. LittlePipeline is a small example of how to create a pipeline that can be tested, and used with any common IoC container. This is a very basic example. It is not designed to handle concurrent tasks. The idea is to use it to express a sequence of steps that must happen to complete a process.

Note: v3 is something of a breaking change. The library now only targets .NET Std 2.0.

Getting started.

You will need a subject. This is the class upon which the process is being performed. Subjects must be a class.

public class Counter
{
    public int Value { get; set; }
}

You will need one or more tasks. Tasks must implement the ITask<TSubject> interface.

public class Increment : ITask<Counter>
{
    public void Run(Counter counter)
    {
        counter.Value++;
    }
}

Once your subject, and tasks are defined, it's time to setup the task factory. LittlePipeline comes with a very basic task factory which can be used if you're not using an IoC container in your application. Each task must be registered in the task factory.

var pipeline = MakePipeline.ForSubject<FirstTestSubject>()
    .With<Increment>(() => new Increment())
    .Build();

Using the pipeline is pretty easy after that:

var subject = new FirstTestSubject();
pipeline.Subject(subject);
pipeline.Do<Increment>();

What about async methods?

LittlePipeline supports async methods. To use async operations, the tasks must be defined as asynchronous:

public class Incrementer : IAsyncTask<Counter>
{
    public Task Run(Counter counter)
    {
        await Task.Run(() => counter.Value++);
    }
}

Then, simply use the DoAsync<T>() method, instead of the normal method:

var subject = new FirstTestSubject();
pipeline.Subject(subject);
await pipeline.DoAsync<Incrementer>();

How do I use it with my IoC container?

Ninject

Using the pipeline with an IoC container is pretty easy. Just register the task factory, tasks, and pipeline with your container. Here's an example using Ninject:

var kernel = new StandardKernel();
kernel.Bind<ITaskFactory>().ToFactory();

kernel.Bind<Increment>().ToSelf();
kernel.Bind<Square>().ToSelf();

kernel.Bind(typeof(IPipeline<>)).To(typeof(Pipeline<>));

Then, just resolve and use the pipeline normally (or inject it into another class):

var pipeline = kernel.Get<IPipeline<FirstTestSubject>>();

var subject = new FirstTestSubject();
pipeline.Subject(subject);
pipeline.Do<Increment>();

Autofac

var builder = new ContainerBuilder();

builder.RegisterType<TaskFactory>().As<ITaskFactory>().SingleInstance();

builder.RegisterType<Increment>().AsSelf();
builder.RegisterType<Square>().AsSelf();

builder.RegisterGeneric(typeof(Pipeline<>)).As(typeof(IPipeline<>)).AsImplementedInterfaces();

var container = builder.Build();

var pipeline = container.Resolve<IPipeline<FirstTestSubject>>();

var subject = new FirstTestSubject();
pipeline.Subject(subject);
pipeline.Do<Increment>();
pipeline.Do<Increment>();
pipeline.Do<Square>();

A very simple factory class...

public class TaskFactory(IComponentContext container) : ITaskFactory
{
    public TTask Create<TTask>() where TTask : ITask =>
        container.Resolve<TTask>();

    public TTask CreateAsync<TTask>() where TTask : IAsyncTask =>
        container.Resolve<TTask>();
}

How do I test the pipeline?

Testing the pipeline's use is as easy as testing that calls were made in the correct order. First, the class that's using a pipeline:

public class ThingThatUsesThePipeline
{
    private readonly IPipeline<FirstTestSubject> pipeline;

    public ThingThatUsesThePipeline(IPipeline<FirstTestSubject> pipeline)
    {
        this.pipeline = pipeline;
    }

    public void Run(FirstTestSubject subject)
    {
        pipeline.Subject(subject);
        pipeline.Do<Increment>();
        pipeline.Do<Square>();
    }
}

And here's the tests using FakeItEasy:

var pipeline = A.Fake<IPipeline<FirstTestSubject>>();
var example = new ThingThatUsesThePipeline(pipeline);


var subject = new FirstTestSubject();
example.Run(subject);

A.CallTo(() => pipeline.Subject(subject)).MustHaveHappened()
    .Then(A.CallTo(() => pipeline.Do<Increment>()).MustHaveHappened())
    .Then(A.CallTo(() => pipeline.Do<Square>()).MustHaveHappened());

Known Issues

No known issues.

Version History

v3.0.0

  • Solely targets .NET Std 2.0.

v2.0.0

  • Upgraded to use .NET Standard

v1.1.0

  • Support for async tasks.
  • Support for .NET 4.6.1.
  • Various dependencies updated.

v1.0.0

  • Initial release, supporting .NET 4.5.2, and 4.6.2.
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 was computed. 
.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.
  • .NETStandard 2.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.

Version Downloads Last updated
3.0.0 126 5/10/2024
2.0.0.55 995 3/20/2020
2.0.0.54 466 3/20/2020
2.0.0.53 460 3/20/2020
2.0.0.52 464 3/20/2020
2.0.0.51 465 3/20/2020
1.1.0.34 1,082 7/12/2018
1.1.0.31 958 7/2/2018
1.0.0.29 1,590 8/9/2017
1.0.0.28 977 8/8/2017
1.0.0.27 1,055 8/8/2017
1.0.0.26 980 8/8/2017
1.0.0.25 1,069 8/8/2017
0.1.0 1,040 8/3/2017