Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to MediatR

Introduction to MediatR

Presentation made at Criteo Full-Stack Tech Talks meetup!

Abstract:
CQRS, Messaging Handling, you do it in your .Net Core project and you don’t know MediatR?
This library developed by the American MVP Jimmy Bogard contains everything you need to organize your project correctly. In this presentation, we will focus on the issue dealt with by MediatR.
We will then discuss the capabilities of the library and its implementation to craft microservices in DDD.

Sylvain PONTOREAU

March 14, 2019
Tweet

More Decks by Sylvain PONTOREAU

Other Decks in Programming

Transcript

  1. GetOrderById Query UpdateProduct Command GetProducts Query DeleteOrder Command … …

    Dispatcher QueryHandler Read DB Dispatcher QueryHandler QueryHandler QueryHandler QueryHandler QueryHandler CommandHandler CommandHandler CommandHandler CommandHandler CommandHandler CommandHandler Write DB
  2. public class GetUserById : IRequest<User> { public Guid Id {

    get; } public GetUserById(Guid id) { Id = id; } } public class DeleteUser : IRequest<Unit> { public Guid Id { get; } public DeleteUser(Guid id) { Id = id; } }
  3. IServiceCollection services = new ServiceCollection(); services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly); IServiceProvider provider = services.BuildServiceProvider();

    IMediator mediator = provider.GetService<IMediator>(); User user = mediator.send(new GetUserById( "052ee87a-8ff5-4aa6-8f0d-3cd417e34e74" ));