Skip to content

Instantly share code, notes, and snippets.

@jeremydmiller
Last active December 6, 2022 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremydmiller/f8ca09d2305b7f7cd3c9da863bda797a to your computer and use it in GitHub Desktop.
Save jeremydmiller/f8ca09d2305b7f7cd3c9da863bda797a to your computer and use it in GitHub Desktop.
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