Last active
December 6, 2022 22:08
-
-
Save jeremydmiller/f8ca09d2305b7f7cd3c9da863bda797a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DebitAccountHandler1928499868 : Wolverine.Runtime.Handlers.MessageHandler | |
{ | |
private readonly Wolverine.FluentValidation.IFailureAction<AppWithMiddleware.DebitAccount> _failureAction; | |
private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; | |
private readonly FluentValidation.IValidator<AppWithMiddleware.DebitAccount> _validator; | |
public DebitAccountHandler1928499868(Wolverine.FluentValidation.IFailureAction<AppWithMiddleware.DebitAccount> failureAction, Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory, FluentValidation.IValidator<AppWithMiddleware.DebitAccount> validator) | |
{ | |
_failureAction = failureAction; | |
_outboxedSessionFactory = outboxedSessionFactory; | |
_validator = validator; | |
} | |
public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) | |
{ | |
var debitAccount = (AppWithMiddleware.DebitAccount)context.Envelope.Message; | |
await using var documentSession = _outboxedSessionFactory.OpenSession(context); | |
(var handlerContinuation, var account) = await AppWithMiddleware.AccountLookupMiddleware.BeforeAsync((AppWithMiddleware.IAccountCommand)context.Envelope.Message, documentSession, cancellation).ConfigureAwait(false); | |
if ((var handlerContinuation, var account) == Wolverine.HandlerContinuation.Stop) return; | |
Wolverine.FluentValidation.Internals.FluentValidationExecutor.ExecuteOne<AppWithMiddleware.DebitAccount>(_validator, _failureAction, debitAccount); | |
AppWithMiddleware.DebitAccountHandler.Handle(debitAccount, account, documentSession); | |
// Commit the unit of work | |
await documentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment