public static ItemCreated Handle( // This would be the message CreateItemCommand command, // Any other arguments are assumed // to be service dependencies IDocumentSession session) { // Create a new Item entity var item = new Item { Name = command.Name }; // Add the item to the current // session unit of work session.Store(item); // This event being returned // by the handler will be automatically sent // out as a "cascading" message return(new ItemCreated { Id = item.Id }); }
public async Task Create([FromBody] CreateItemCommand command) { // Start the "Outbox" transaction await _messaging.EnlistInTransaction(_session); // Create a new Item entity var item = new Item { Name = command.Name }; // Add the item to the current // IDocumentSession unit of work _session.Store(item); // Publish an event to anyone // who cares that a new Item has // been created var @event = new ItemCreated { Id = item.Id }; // Because the message context is enlisted in an // "outbox" transaction, these outgoing messages are // held until the ongoing transaction completes await _messaging.Send(@event); // Commit the unit of work. This will persist // both the Item entity we created above, and // also a Jasper Envelope for the outgoing // ItemCreated message. If the operation // succeeds, the outgoing Jasper messages will // be released to Jasper's sending agents await _session.SaveChangesAsync(); }
public Task <ItemCreated> Create([FromBody] CreateItemCommand command) { // Using Jasper as a Mediator, and receive the // expected response from Jasper return(_bus.Invoke <ItemCreated>(command)); }
public Task Create([FromBody] CreateItemCommand command) { // Using Jasper as a Mediator return(_bus.Invoke(command)); }