An open API service indexing awesome lists of open source software.

https://github.com/subethasensomatic/pipeline

Asynchronous ASP.NET Core like pipeline implementation
https://github.com/subethasensomatic/pipeline

asynchronous csharp dotnet-core patterns pipeline

Last synced: 3 months ago
JSON representation

Asynchronous ASP.NET Core like pipeline implementation

Awesome Lists containing this project

README

          

# pipeline
Asynchronous ASP.NET Core like pipeline implementation

### Usage

Create a context Class ...
```csharp
public class MyPipelineContext
{
public string SharedInformationBetweenItems { get; set; }
}
```

Create items for your pipeline ...

```csharp
public class MyPipelineItem: IPipelineItem
{
public async Task run(MyPipelineContext ctx, Func next)
{
await next();

Console.WriteLine(ctx.SharedInformationBetweenItems);
}
}
```

Configure and run your pipeline ...

```csharp

...

// without dependency injection
// var builder = new PipelineBuilder();

// or with dependency injection
var builder = new PipelineBuilder(itemType => container.Resolve(itemType));

// Add delegate item to pipeline
builder.Use(async (ctx, next) => {
ctx.SharedInformationBetweenItems = "Some text...";

// don't forget to call
await next();
});

// Use item object
builder.Use();

// Build pipeline ...
var pipeline = builder.BuildPipeline();

// ... and run
var myContext = new MyPipelineContext();
await pipeline(myContext);

// ... run again with new context
myContext = new MyPipelineContext();
await pipeline(myContext);

...
```