Class ChainTransformer<TSource, TIntermediate, TDestination>
- Namespace
- Wolfgang.Etl.Transformers
- Assembly
- Wolfgang.Etl.Transformers.dll
Combines two transformers into a single transformer: items flow through the first, then through the second, with the intermediate type erased from the chain's public signature.
public sealed class ChainTransformer<TSource, TIntermediate, TDestination> : ITransformAsync<TSource, TDestination> where TSource : notnull where TIntermediate : notnull where TDestination : notnull
Type Parameters
TSourceThe input type of the chain (the input type of the first transformer). Must be non-null.
TIntermediateThe output type of the first transformer and input type of the second. Must be non-null.
TDestinationThe output type of the chain (the output type of the second transformer). Must be non-null.
- Inheritance
-
ChainTransformer<TSource, TIntermediate, TDestination>
- Implements
-
ITransformAsync<TSource, TDestination>
- Inherited Members
- Extension Methods
Remarks
ChainTransformer<TSource, TIntermediate, TDestination> is the building block for composing multi-stage transformer pipelines as a single Wolfgang.Etl.Abstractions.ITransformAsync<TSource, TDestination> that can be passed to a loader, registered in DI, or otherwise treated as a unit.
For chains longer than two stages, prefer the Then<TSource, TIntermediate, TDestination>(ITransformAsync<TSource, TIntermediate>, ITransformAsync<TIntermediate, TDestination>) extension method, which nests ChainTransformer<TSource, TIntermediate, TDestination> instances and lets the C# compiler infer all type parameters:
// 5-stage pipeline, all intermediate types inferred
var pipeline = parseRaw
.Then(normalize)
.Then(lookupCustomer)
.Then(validate)
.Then(formatForLoad);
Implements only Wolfgang.Etl.Abstractions.ITransformAsync<TSource, TDestination> - matching the lightweight pattern of the rest of the library. The chain itself adds no per-item state-machine wrapping; it returns the inner transformers' enumerables composed directly.
Formerly known internally as MultiStepTransformer.
Constructors
ChainTransformer(ITransformAsync<TSource, TIntermediate>, ITransformAsync<TIntermediate, TDestination>)
Initializes a new instance with the two transformers that make up the chain.
public ChainTransformer(ITransformAsync<TSource, TIntermediate> first, ITransformAsync<TIntermediate, TDestination> second)
Parameters
firstITransformAsync<TSource, TIntermediate>The first transformer; consumes
TSourceitems and producesTIntermediateitems.secondITransformAsync<TIntermediate, TDestination>The second transformer; consumes
TIntermediateitems and producesTDestinationitems.
Exceptions
- ArgumentNullException
firstorsecondis null.
Methods
TransformAsync(IAsyncEnumerable<TSource>)
Asynchronously yields each item from items after passing it through
the first transformer and then the second.
public IAsyncEnumerable<TDestination> TransformAsync(IAsyncEnumerable<TSource> items)
Parameters
itemsIAsyncEnumerable<TSource>The asynchronous source sequence.
Returns
- IAsyncEnumerable<TDestination>
An asynchronous sequence of the items produced by the second transformer.
Exceptions
- ArgumentNullException
itemsis null.