Interface ISagaCorrelationRegistry
Holds the declared correlation for each saga type and message type, so the coordinator can decide which saga instance a message belongs to without the publisher computing an identifier.
public interface ISagaCorrelationRegistry
- Extension Methods
Remarks
Why this is a registry and not a method on the saga. The coordinator needs the correlation BEFORE it has an instance, because the correlation is what produces the identifier it would load the instance by. An instance method could not be reached in time, so the declaration is registered per saga type at composition and read from here.
What it stores is a typed closure, not a property name. A registration captures the consumer's
own Func<TMessage, string>, so extracting the key is a direct call. Nothing is looked up
by name, nothing is reflected over, and the whole path survives trimming and Native AOT — which a
property-name-based correlation would not.
Methods
TryResolveSagaId(Type, object, out Guid)
Resolves the saga identifier for message from the correlation declared for
sagaType.
bool TryResolveSagaId(Type sagaType, object message, out Guid sagaId)
Parameters
sagaTypeTypeThe saga type the message is being routed to.
messageobjectThe message carrying the business key.
sagaIdGuidThe derived identifier, when a correlation is declared and yielded a key.
Returns
- bool
true when a correlation is declared for this saga and message type and it produced an identifier; false when no correlation is declared, which leaves the caller to use whatever identifier the message carries itself.
Remarks
The two negative answers are deliberately not the same thing. Returning false means NOTHING WAS DECLARED, and the caller should fall back. A declaration that exists and yields no key is a different situation entirely — the consumer said this message correlates and it does not — and an implementation must THROW rather than return false, because falling back there would route the message by whatever identifier it happened to carry and silently start a second saga.