Class SmartMerger<TCommand, TAggregate>
- Namespace
- Stratara.Shared.Merging.SmartMerging
- Assembly
- Stratara.Shared.dll
Property-by-property smart-merge of an incoming TCommand against the live
TAggregate state. For each property that exists on both types with a
matching CLR type, the value wins as follows: if the command's value equals the source aggregate
value the caller observed (no intent to change), the current live value wins; otherwise the
command's value wins.
public static class SmartMerger<TCommand, TAggregate> where TCommand : new()
Type Parameters
TCommandCLR type of the update command. Must be parameterless-constructable so the merger can create a fresh result.
TAggregateCLR type of the aggregate / read model.
- Inheritance
-
SmartMerger<TCommand, TAggregate>
- Inherited Members
Remarks
Property accessors are compiled and cached per-type-combination via PropertyAccessorCache. Properties that do not exist on both types or whose CLR types differ are ignored.
Methods
Merge(TCommand, TAggregate, TAggregate)
Returns a fresh TCommand with each property resolved by the
smart-merge rules described on SmartMerger<TCommand, TAggregate>.
public static TCommand Merge(TCommand originalCommand, TAggregate source, TAggregate current)
Parameters
originalCommandTCommandThe incoming command authored against
source.sourceTAggregateThe aggregate state the caller observed when authoring the command.
currentTAggregateThe live aggregate state to merge against.
Returns
- TCommand
A new
TCommandwith the merged property values.