JasperFx / jasper

Next generation application development framework for .Net
http://jasperfx.github.io/
MIT License
420 stars 54 forks source link

Middleware convention for Marten command handlers #721

Closed jeremydmiller closed 2 years ago

jeremydmiller commented 2 years ago

The goal here is to make it as easy as possible to have a handler method that:

  1. Uses Marten's FetchForWriting() method to find the right aggregate for the command
  2. Takes in a command message, a Marten event sourced aggregate (or the handle method is on the actual aggregate), and any other arguments for other services
  3. applies any cascading events to the event stream for the aggregate
  4. Calls `IDocumentSession.SaveChangesAsync()
[MartenAggregate]
public class SomeAggregate
{
    SpecificEvent Handle(SomeCommand cmd);

    void Handle(IncomingEvent @event, IEventStream stream);

    IEnumerable<object> Handle(SomeCommand cmd);

    Task<SpecificEvent> Handle(SomeCommand cmd);

    Task Handle(SomeCommand cmd, IEventStream stream);
}

or

public class AnyClass
{
    Task Handle(Command cmd, Aggregate aggregate, IEventStream);
}