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!

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.

More Decks by pontoreau.sylvain@gmail.com

Other Decks in Programming


  1. Criteo FullStack Tech Talks March, 2019

  2. Premier Field Engineer @spontoreau In ❤️ with Co-organizer

  3. None
  4. None
  5. Mediator obj obj obj obj obj obj obj obj

  6. None
  7. Query Just a read operation Command Data validation Business logic

  8. 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
  9. 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; } }
  10. public class GetUserByIdHandler : IRequestHandler<GetUserById, User> { public Task<User> Handle(GetUserById

    request, CancellationToken cancellationToken) { // … } }
  11. 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" ));
  12. None
  13. https://github.com/jbogard/MediatR https://ardalis.com/using-mediatr-in-aspnet-core-apps https://en.wikipedia.org/wiki/Mediator_pattern https://www.martinfowler.com/bliki/CQRS.html https://docs.microsoft.com/en-us/azure/architecture/patterns/cqrs https://github.com/spontoreau/MediatorPatternExample https://github.com/spontoreau/DemoMediatR

  14. None
  15. None