NPipeline Extensions
NPipeline's modular design allows its core functionality to be extended through separate NuGet packages. These extensions provide specialized nodes, integration points, and advanced features that cater to specific use cases without bloating the core library.
This section details the officially supported extensions and how to leverage them in your pipelines.
Available Extensions
-
Dependency Injection: Seamlessly integrate NPipeline with your favorite Dependency Injection container. Learn how to use constructor injection in your nodes and run pipelines with the
RunPipelineAsync<TDefinition>()extension method. -
Parallelism: Execute pipeline nodes in parallel for improved performance. Discover how to use
ParallelExecutionStrategywithWithParallelOptions()to configure parallel processing, queue policies, and ordering behavior. -
Testing: Utilities and helpers for writing comprehensive and efficient tests for your pipelines. Includes in-memory source/sink nodes, pipeline builder extensions, and assertion libraries.
-
Connectors: Pre-built source and sink nodes for common data sources and destinations (e.g., CSV files).
Extension Packages
Core Extensions
| Package | Description | Key Features |
|---|---|---|
NPipeline.Extensions.DependencyInjection | DI container integration | Constructor injection, service lifetime management, RunPipelineAsync() extension |
NPipeline.Extensions.Parallelism | Parallel processing capabilities | ParallelExecutionStrategy, WithParallelOptions(), queue policies |
NPipeline.Extensions.Testing | Testing utilities | In-memory nodes, pipeline builder extensions, test context helpers |
Assertion Libraries
| Package | Description | Integration |
|---|---|---|
NPipeline.Extensions.Testing.AwesomeAssertions | AwesomeAssertions integration | ShouldHaveReceived(), ShouldContain(), ShouldOnlyContain() |
NPipeline.Extensions.Testing.FluentAssertions | FluentAssertions integration | ShouldHaveReceived(), ShouldContain(), ShouldNotContain() |
Getting Started with Extensions
Installation
Each extension is available as a separate NuGet package. Install only what you need:
# Dependency Injection
dotnet add package NPipeline.Extensions.DependencyInjection
# Parallelism
dotnet add package NPipeline.Extensions.Parallelism
# Testing
dotnet add package NPipeline.Extensions.Testing
# Testing with AwesomeAssertions
dotnet add package NPipeline.Extensions.Testing.AwesomeAssertions
dotnet add package AwesomeAssertions
# Testing with FluentAssertions
dotnet add package NPipeline.Extensions.Testing.FluentAssertions
dotnet add package FluentAssertions
Basic Usage Pattern
Most extensions follow a consistent pattern:
- Install the NuGet package
- Add using statements for the extension namespace
- Use extension methods on
PipelineBuilder,IServiceCollection, or test classes - Configure options as needed for the extension
using NPipeline.Extensions.DependencyInjection;
using NPipeline.Extensions.Parallelism;
using NPipeline.Extensions.Testing;
// DI setup
var services = new ServiceCollection();
services.AddNPipeline(Assembly.GetExecutingAssembly());
// Parallel pipeline definition
public class MyParallelPipeline : IPipelineDefinition
{
public void Define(PipelineBuilder builder, PipelineContext context)
{
var source = builder.AddInMemorySource<int>();
var transform = builder.AddTransform<MyTransform, int, int>();
var sink = builder.AddInMemorySink<int>();
builder.Connect(source, transform);
builder.Connect(transform, sink);
// Configure parallel execution
builder.WithParallelOptions(transform,
new ParallelOptions { MaxDegreeOfParallelism = 4 });
transform.ExecutionStrategy = new ParallelExecutionStrategy();
}
}
Best Practices
- Install only what you need: Each extension is a separate package to keep your dependencies minimal
- Use the right tool for the job: Leverage testing extensions for unit tests, parallelism for performance, DI for enterprise applications
- Combine extensions: Extensions are designed to work together seamlessly
- Check compatibility: Ensure extension versions are compatible with your NPipeline core version
Next Steps
- Dependency Injection: Learn about constructor injection and service lifetime management
- Parallelism: Explore parallel processing capabilities and configuration options
- Testing: Discover comprehensive testing utilities and assertion libraries
- Connectors: Explore pre-built connectors for external systems