Questions tagged [mediatr]

MediatR is a simple, open source mediator implementation in .NET.

MediatR is a simple, open source, mediator implementation in .NET

A low-ambition library trying to solve a simple problem - decoupling the in-proc sending of messages from handling messages. Cross-platform, supporting .NET 4.5, .NET Standard 1.3, and .NET Standard 2.0.

Supports request/response, commands, queries, notifications and events, synchronous and async with intelligent dispatching via C# generic variance.

See https://github.com/jbogard/MediatR/wiki for more details.

507 questions
9
votes
3 answers

Return response with errors instead of throwing exception in validation pipeline mediatr 3

I am currently working with Pipeline behavior in Mediatr 3 for request validation. All the examples that I came across were throwing ValidationException if any failures happening, instead of doing that I want to return the response with the error.…
anggiputper
  • 193
  • 1
  • 9
9
votes
2 answers

Register a MediatR pipeline with void/Task response

My command: public class Command : IRequest { ... } My handler: public class CommandHandler : IAsyncRequestHandler { ... } My pipeline registration (not using open generics): services.AddTransient,…
grokky
  • 8,537
  • 20
  • 62
  • 96
9
votes
1 answer

How to test with MediatR

I've just started out testing MediatR to clean up our heavy involved web controllers. Implementing the functionality it self isn't hard at all, but I struggle a little with testing. I started out with a controller method for canceling a order. When…
Vegar
  • 12,828
  • 16
  • 85
  • 151
8
votes
1 answer

IMediatR - Generic Request Handler for generic Requests

I'm currently facing a problem with IMediatR IRequestHandlers and IRequest. To give a little bit of context, on our tool, the user can request access to the tool by filling a couple of fields. Currently, we have two levels of access, meaning we…
8
votes
1 answer

Using multiple FluentValidators on MediatR pipeline

I have a MediatR pipeline behavior like this: public class FailFastRequestBehavior : IPipelineBehavior { private readonly IEnumerable _validators; public…
rbasniak
  • 4,484
  • 11
  • 51
  • 100
8
votes
2 answers

Constraint Violated Exception on MediatR Behavior

I am using MediatR with the following classes: public class GetPostsRequest : IRequest> { public Int32 Age { get; set; } } public class GetPostResponse { public String Title { get; set; } public String Content {…
Miguel Moura
  • 36,732
  • 85
  • 259
  • 481
8
votes
2 answers

How do I manually register Mediatr handlers, in ASP.NET Core?

I'm using ASP.NET Core, with the built-in container. Automatic registration is supposed to be done like so: services.AddMvc(); services.AddMediatR(typeof(Startup)); This automatically 1) configures MediatR, and 2) registers all handlers found in…
grokky
  • 8,537
  • 20
  • 62
  • 96
8
votes
1 answer

Handling errors/exceptions in a mediator pipeline using CQRS?

I'm trying to follow this post by Jimmy Bogard to implement a mediator pipeline so I can use pre/post request handlers to do some work. From the comments on that article I come to this github gist. I don't quite understand how to hook all of this up…
BBauer42
  • 3,549
  • 10
  • 44
  • 81
7
votes
3 answers

How does MediatR know which handler to call?

I'm learning MediatR and I have a problem connecting the Controller to the Handler. Controller: [HttpGet] public async Task> Get() { return await _mediator.Send(new GetPersonListQuery()); } My understanding is that the…
EBDS
  • 1,244
  • 5
  • 16
7
votes
1 answer

MediatR Notifications with Blazor (WASM) - Event handler does not update UI

I'm trying to hook up MediatR in a client-side Blazor application purely to handle event notifications between components. The event is published, and it gets picked up by a separate component with a handler, but I can't update the UI from the…
pfeds
  • 2,183
  • 4
  • 32
  • 48
7
votes
3 answers

Mediatr handlers are they singletons?

I am using the Mediatr in my .Net Core project and I was wondering if the handler's in the Mediatr are singleton's or are the new instances for every Send request; I know the Mediatr is a Singleton' but for the handlers it uses for a command or…
Dhiru
  • 159
  • 2
  • 5
7
votes
0 answers

ASP.NET Core 3.0 - Cannot access a disposed object. Object name: 'IServiceProvider'

We have windows service that hosts web api and does some calculation job in background. From time to time we get exception: 2019-12-27 11:49:15.525 +01:00 [Error] [Serilog.Log.Write] Unhandled exception caught. Runtime is terminating :…
7
votes
2 answers

Cannot inject HttpClient in typed client while using with IMediatR library

According to examples provided by ASP.NET Core 2.2 documentation in MSDN, it is possible to inject HttpClient to a typed clients (service-classes) by adding the following line to Startup.cs: //…
Iskander Raimbaev
  • 1,322
  • 2
  • 17
  • 35
7
votes
2 answers

BasePageModel in Razor Pages

I'm currently refactoring a bloated MVC .NET Core app to a more simpler .NET Core app using Razor Pages and Mediatr. In the MVC approach there's a BaseController that all controllers inherits from. The BaseController handles the Mediatr DI. How will…
KlaasJan
  • 193
  • 2
  • 12
7
votes
2 answers

Mediatr - Where is the right place to invalidate/update cache

This question stems from this other question I had asked about too many interfaces, QCRS and Mediatr library (request/response) Mediatr: reducing number of DI'ed objects I have created bunch of commands and queries and I have bunch of behaviors and…
Zoinky
  • 4,083
  • 11
  • 40
  • 78
1 2
3
33 34