Interface IPersistOnFailure
- Namespace
- Trellis
- Assembly
- Trellis.Core.dll
Opt-in interface implemented by result types whose failure outcome should still
trigger any post-handler persistence step (e.g. TransactionalCommandBehavior's
commit) so the failure state is durably recorded alongside the rest of the staged work.
public interface IPersistOnFailure
- Extension Methods
Remarks
The canonical use case is a worker handler that converts a transient external-service
failure into a persisted "rejected" or "permanently_failed" row on the corresponding
aggregate. The handler stages the state-change-to-failed via the change tracker, then
returns FailAfterCommit<TValue>(Error). TransactionalCommandBehavior
observes PersistOnFailure = true and commits the staged
row even though the result is a failure. The caller still receives the original
Error — the result is still a failure.
PersistOnFailure is a per-instance property, not a type-level marker.
Implementations like Result<TValue> implement this interface unconditionally
(the same struct represents both ordinary and persist-on-failure outcomes) and return
the per-instance flag. A type-only is IPersistOnFailure check is therefore insufficient
and would incorrectly include ordinary Fail<TValue>(Error) values;
consumers must use a property-bound pattern such as
result is IPersistOnFailure { PersistOnFailure: true }.
The flag is meaningless on success — successful results commit unconditionally — and
implementations should return false on success to keep the
IsSuccess || PersistOnFailure idiom unambiguous.
Properties
PersistOnFailure
Gets a value indicating whether a failed result should still trigger the post-handler persistence step.
bool PersistOnFailure { get; }
Property Value
- bool
true when this instance was created by a persist-on-failure factory (such as FailAfterCommit<TValue>(Error)) or projected / aggregated from such an instance by a railway operator; otherwise false.