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
15
votes
5 answers

How to add mediatr in .NET 6?

In .NET Core, we can add it in ConfigureServices method services.AddMediatR(typeof(Startup)); But in .NET 6, there is only Program.cs. How to add mediatr in .NET 6? Tried with this code but got build error
Steve
  • 2,963
  • 15
  • 61
  • 133
15
votes
2 answers

Unable to resolve service for type 'MediatR.IMediator'

I try to make .NET Core API with CQRS, but i cannot build it because of MediatR error: System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType:…
ervin
  • 329
  • 1
  • 2
  • 12
15
votes
6 answers

DDD: Referencing MediatR interface from the domain project

I'm just getting started with DDD. I'm putting domain events into a CQRS application and I'm stumbling on a fundamental task: How to use the MediatR.INotification marker interface within the domain project without creating a domain dependency on…
platypusjh
  • 667
  • 1
  • 7
  • 16
14
votes
3 answers

Is MediatR library overused in CQRS examples on the web?

I'm struggling to understand why so many examples on the web are using MediatR when explaining CQRS patterns, when dealing with commands and queries. Almost everywhere I see examples where Commands and Queries are handled by MediatR but I do not see…
Tomasz Sikora
  • 1,649
  • 3
  • 19
  • 30
14
votes
4 answers

Clean Architecture CQRS with GraphQL API

I'm working on an API server (ASP.NET Core). To prevent spaghetti code and other nastiness in the future, I design the system following Clean Architecture/CQRS (using MediatR). I'm considering to use GraphQL for the API instead of REST (Hot…
Arthur Kater
  • 826
  • 10
  • 17
14
votes
1 answer

How do I register and use a MediatR pipeline handler, for ASP.NET Core?

I'm using ASP.NET Core, the latest MediatR, and MediatR extension for Core's DI. I'm trying to set up a pipeline with validation, using the official blog post. The example is here. I don't understand how to register/use that pipeline class. Another…
grokky
  • 8,537
  • 20
  • 62
  • 96
13
votes
1 answer

Why doesn't Mediatr resolve method when entites are in different projects?

I have a simple project to try out Mediatr issue. When the concrete class of my handler in the SAME project of my API, it WORKS. But, when I take that handler class in to a different project (and API references that project ofc), it does NOT resolve…
E-A
  • 195
  • 1
  • 2
  • 10
13
votes
3 answers

Mediatr 3.0 Using Pipeline behaviors for authentication

Looking at using the new Mediatr 3.0 feature pipeline behaviors for authentication/authorization. Would you normally auth based on the message or the handler? reason I'm asking is that I'd auth on the handler (same as controller in MVC) but…
Betty
  • 9,109
  • 2
  • 34
  • 48
12
votes
1 answer

HttpContext.RequestServices.GetService() vs services.AddScope()?

In the following code (from https://github.com/JasonGT/NorthwindTraders/blob/master/Src/WebUI/Controllers/BaseController.cs), it's a base control inherited by all controllers. [ApiController] [Route("api/[controller]/[action]")] public abstract…
ca9163d9
  • 27,283
  • 64
  • 210
  • 413
11
votes
3 answers

MediatR CQRS - How to deal with unexisting resources (asp.net core web api)

So I've recently started to learn about using the MediatR library with ASP.NET Core Web API and I'm unsure how to go about returning a NotFound() when a DELETE/PUT/PATCH request has been made for an unexisting resource. If we take DELETE for…
rejy11
  • 742
  • 2
  • 12
  • 25
11
votes
3 answers

ASP.NET infrastructure in MediatR handlers

I prefer to keep my handlers free from ASP.NET infrastructure that is very hard to test (yes, even in ASP.NET Core). But sometimes it happens and you have a dependency like UserManager (I'd like to know one day why it's not an interface),…
SiberianGuy
  • 24,674
  • 56
  • 152
  • 266
10
votes
2 answers

Can we use RabbitMQ and Mediatr together using masstransit?

I created a microservice application that microservices using MassTransit and RabbitMQ for communication. Each microservice developed using clean architecture, so we have MediatR inside each microservice. Is it possible to use MassTransit for inside…
Mahdi
  • 725
  • 2
  • 7
  • 24
9
votes
1 answer

The name `Foo` was already registered by another type, GraphQL

I am using GraphQL as a part of my CQRS application. I have separated Command and Query domain model into two different projects (Query and Command). each of there projects has some models for instance Student model. I use two different model in…
Ocelot
  • 203
  • 3
  • 11
9
votes
1 answer

How do I use query parameters in attributes?

I want to use query parameters in my endpoint attributes but I'm not sure how to use them. I tried this: [HttpPost("fooBar/{version}?amount={amount}&date={date}")] But I get this error instead:…
Euridice01
  • 2,510
  • 11
  • 44
  • 76
9
votes
2 answers

Chaining Handlers with MediatR

We are using MediatR to implement a "Pipeline" for our dotnet core WebAPI backend, trying to follow the CQRS principle. I can't decide if I should try to implement a IPipelineBehavior chain, or if it is better to construct a new Request and call…
gakera
  • 3,589
  • 4
  • 30
  • 36
1
2
3
33 34