| | | 1 | | namespace ProjectTemplate.Infrastructure.Data.Auditing; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Identifies who owns the database transaction used by an audited mutation. |
| | | 5 | | /// </summary> |
| | | 6 | | public enum ApplicationAuditedTransactionOwnership |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// The coordinator created and committed the transaction. |
| | | 10 | | /// </summary> |
| | | 11 | | CoordinatorOwned, |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// The coordinator joined an existing EF Core transaction and protected its work with a savepoint. |
| | | 15 | | /// The caller still owns the final commit or rollback. |
| | | 16 | | /// </summary> |
| | | 17 | | ExistingTransaction |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Summarizes an audited transaction execution without exposing audited entity values. |
| | | 22 | | /// </summary> |
| | | 23 | | /// <param name="MutationSaveChangesCount">The number of state entries written by the mutation save.</param> |
| | | 24 | | /// <param name="CompletionSaveChangesCount">The number of state entries written by the optional local completion save.< |
| | | 25 | | /// <param name="AuditReceipt">The mutation audit receipt produced by the mutation save, when auditing produced a batch. |
| | | 26 | | /// <param name="Ownership">The database transaction ownership model used for the execution.</param> |
| | | 27 | | /// <param name="UsedSavepoint">Whether the coordinator created a savepoint inside an existing transaction.</param> |
| | 10 | 28 | | public sealed record ApplicationAuditedTransactionResult( |
| | 2 | 29 | | int MutationSaveChangesCount, |
| | 2 | 30 | | int CompletionSaveChangesCount, |
| | 6 | 31 | | ApplicationMutationAuditReceipt? AuditReceipt, |
| | 14 | 32 | | ApplicationAuditedTransactionOwnership Ownership, |
| | 14 | 33 | | bool UsedSavepoint) |
| | | 34 | | { |
| | | 35 | | /// <summary> |
| | | 36 | | /// Gets a value indicating whether the coordinator committed the database transaction before returning. |
| | | 37 | | /// </summary> |
| | 10 | 38 | | public bool CommittedByCoordinator => Ownership == ApplicationAuditedTransactionOwnership.CoordinatorOwned; |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Gets a value indicating whether the caller must still commit the existing outer transaction. |
| | | 42 | | /// </summary> |
| | 4 | 43 | | public bool RequiresOuterCommit => Ownership == ApplicationAuditedTransactionOwnership.ExistingTransaction; |
| | | 44 | | } |