You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Classes for building composable async pipelines supporting:
3
+
The `Hyperbee.Pipeline` library is a sophisticated tool for constructing asynchronous fluent pipelines in .NET. A pipeline, in this context, refers to a sequence of data processing elements arranged in series, where the output of one element serves as the input for the subsequent element.
A distinguishing feature of the `Hyperbee.Pipeline` library, setting it apart from other pipeline implementations, is its inherent support for **middleware** and **dependency injection**. Middleware introduces a higher degree of flexibility and control over the data flow, enabling developers to manipulate data as it traverses through the pipeline. This can be leveraged to implement a variety of functionalities such as eventing, caching, logging, and more, thereby enhancing the customizability of the code.
11
6
12
-
## Usage
7
+
Furthermore, the support for dependency injection facilitates efficient management of dependencies within the pipeline. This leads to code that is more maintainable and testable, thereby improving the overall quality of the software.
Hyperbee pipelines come with the ability to enhance processing with custom middleware. The `PipelineFactory` library provides functionality that allows you to manipulate the data as it passes through the pipeline. This is done using the `Hook` and `Wrap` methods.
31
+
32
+
### Hook
33
+
34
+
The `Hook` and `HookAsync` methods allow you to add a hook that is called for every statement in the pipeline. This hook takes the current context, the current argument, and a delegate to the next part of the pipeline. It can manipulate the argument before and after calling the next part of the pipeline.
The `Wrap` and `WrapAsync` method allows you to wrap a part of the pipeline. This is useful when you want to apply a transformation to only a part of the pipeline.
factoryServices.ProxyService<IPrincipalProvider>( rootProvider ); // pull from root container
95
+
} );
96
+
```
97
+
98
+
## Advanced Features
99
+
100
+
The `PipelineFactory` library provides a variety of helper methods that allow you to customize the behavior of your pipelines. These methods provide powerful functionality for manipulating data as it passes through the pipeline.
101
+
102
+
### Reduce
103
+
104
+
The `Reduce` and `ReduceAsync` methods allow you to reduce a sequence of elements to a single value. You can specify a reducer function that defines how the elements should be combined, and a builder function that creates the pipeline for processing the elements.
105
+
106
+
### WaitAll
107
+
108
+
The `WaitAll` method allows you to wait for all pipelines to complete before continuing. You can specify a set of builders that create the pipelines to wait for, a reducer function that combines the results of the pipelines.
The `PipeIf` method allows you to conditionally add a step to the pipeline. You can specify a condition function that determines whether the step should be added, a builder function that creates the step, and an optional flag indicating whether middleware should be inherited.
132
+
133
+
### ForEach and ForEachAsync
134
+
135
+
The `ForEach` and `ForEachAsync` methods allow you to apply a pipeline to each element in a sequence. You can specify a builder function that creates the pipeline for processing the elements.
136
+
137
+
```csharp
138
+
varcount=0;
139
+
140
+
varcommand=PipelineFactory
141
+
.Start<string>()
142
+
.Pipe( ( ctx, arg ) =>arg.Split( ' ' ) )
143
+
.ForEach<string>( builder=>builder
144
+
.Pipe( ( ctx, arg ) =>count+=10 )
145
+
)
146
+
.Pipe( ( ctx, arg ) =>count+=5 )
147
+
.Build();
148
+
149
+
awaitcommand( newPipelineContext(), "e f" );
150
+
151
+
Assert.AreEqual( count, 25 );
152
+
```
153
+
154
+
### Call and CallAsync
155
+
156
+
The `Call` and `CallAsync` methods allow you to add a procedure to the pipeline. You can think of these as `Action<T>` and `Pipe` like `Func<T>`.
157
+
158
+
In this example notice that `arg + 9` is not returned from the use of `Call`
159
+
160
+
```csharp
161
+
varcallResult=string.Empty;
162
+
163
+
varcommand=PipelineFactory
164
+
.Start<string>()
165
+
.Pipe( ( ctx, arg ) =>arg+"1" )
166
+
.Pipe( ( ctx, arg ) =>arg+"2" )
167
+
.Call( builder=>builder
168
+
.Call( ( ctx, arg ) =>callResult=arg+"3" )
169
+
.Pipe( ( ctx, arg ) =>arg+"9" )
170
+
)
171
+
.Pipe( ( ctx, arg ) =>arg+"4" )
172
+
.Build();
173
+
174
+
varresult=awaitcommand( newPipelineContext() );
175
+
176
+
Assert.AreEqual( "124", result );
177
+
Assert.AreEqual( "123", callResult );
178
+
```
179
+
180
+
### Chaining Child Pipelines
181
+
182
+
The `PipelineFactory` library allows you to chain pipelines together. Since pipelines are just functions, they can be used as input to other pipelines. This allows you to create complex data processing flows by reusing and chaining together multiple pipelines.
183
+
184
+
Here's an example of how to chain pipelines together:
The `Hyperbee.Pipeline` library is a sophisticated tool for constructing asynchronous fluent pipelines in .NET. A pipeline, in this context, refers to a sequence of data processing elements arranged in series, where the output of one element serves as the input for the subsequent element.
4
+
5
+
A distinguishing feature of the `Hyperbee.Pipeline` library, setting it apart from other pipeline implementations, is its inherent support for **middleware** and **dependency injection**. Middleware introduces a higher degree of flexibility and control over the data flow, enabling developers to manipulate data as it traverses through the pipeline. This can be leveraged to implement a variety of functionalities such as eventing, caching, logging, and more, thereby enhancing the customizability of the code.
6
+
7
+
Furthermore, the support for dependency injection facilitates efficient management of dependencies within the pipeline. This leads to code that is more maintainable and testable, thereby improving the overall quality of the software.
0 commit comments