Skip to content

Instantly share code, notes, and snippets.

@ankitvijay
Last active October 9, 2021 22:15
Show Gist options
  • Save ankitvijay/a2000958c3202b630ac929030ee29db4 to your computer and use it in GitHub Desktop.
Save ankitvijay/a2000958c3202b630ac929030ee29db4 to your computer and use it in GitHub Desktop.
NServiceBus Cosmos Sample - AddPostHandler
public class AddPostHandler : IHandleMessages<AddPost>
{
public async Task Handle(AddPost message, IMessageHandlerContext context)
{
var cosmosSession = context.SynchronizedStorageSession.CosmosPersistenceSession();
var post = new Post(message.PostId, message.Title, message.Description, message.Author);
cosmosSession.Batch.CreateItem(post);
await context.Publish(new PostCreated
{
PostId = post.PostId,
Author = post.Author,
Description = post.Description,
Title = post.Title
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment