Skip to content

Instantly share code, notes, and snippets.

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/175f7676f2e21191342d3fabfa1388c0 to your computer and use it in GitHub Desktop.
Save jeremydmiller/175f7676f2e21191342d3fabfa1388c0 to your computer and use it in GitHub Desktop.
public class ShowHandler_CreateItemCommand : Jasper.Bus.Model.MessageHandler
{
private readonly IDocumentStore _documentStore;
public ShowHandler_CreateItemCommand(IDocumentStore documentStore)
{
_documentStore = documentStore;
}
public override async Task Handle(Jasper.Bus.Runtime.Invocation.IInvocationContext context)
{
var createItemCommand = (ShowHandler.CreateItemCommand)context.Envelope.Message;
// generated by middleware
using (var documentSession = _documentStore.OpenSession())
{
// calling the inner "handler"
var outgoing1 = ShowHandler.CreateItemHandler.Handle(createItemCommand, documentSession);
// generated by standard policies to glue together outgoing messages
context.EnqueueCascading(outgoing1);
// this was generated by transactional middleware
await documentSession.SaveChangesAsync();
}
}
}
@jeremydmiller
Copy link
Author

The actual handler code is this:

    public class CreateItemHandler
    {
        [MartenTransaction]
        public static ItemCreatedEvent Handle(
            CreateItemCommand command, 
            IDocumentSession session)
        {
            var item = new Item {Name = command.Name};
            session.Store(item);

            return new ItemCreatedEvent{Item = item};
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment