Skip to main content
Table of Contents

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

TCommand

CLR type of the update command. Must be parameterless-constructable so the merger can create a fresh result.

TAggregate

CLR 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

originalCommand TCommand

The incoming command authored against source.

source TAggregate

The aggregate state the caller observed when authoring the command.

current TAggregate

The live aggregate state to merge against.

Returns

TCommand

A new TCommand with the merged property values.