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
4
votes
1 answer

Swagger UI and Swagger Doc does not generate query string. .NET 6 Web API with Minimal API, Mediatr, and Swashbuckle

I have build a Web API application using .NET 6, Mediatr, and Swashbuckle ASPNetCore. I am using nTier structure, so there is more than one project for my solutions with my Web API project having reference to a class library project that consist…
4
votes
1 answer

Each parameter in the deserialization constructor on type 'Entities' must bind to an object property or field on deserialization

I have this post method in my controller [HttpPost] public Task Post(AddClientAppSettingCommand mysetting) => Mediator.Send(mysetting); My post method accept an AddClientAppSettingCommand model as you can…
Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180
4
votes
0 answers

C# Autofac+MediatR and IRequestExceptionHandler not working with Net Framework

I'm building a test project (C# and Net Framework 4.7.2) to test CQRS using MediatR(9.0.0) and Autofac(6.3.0) as DI resolver. Command handlers (registered as IRequestHandler<,>) are working fine. The thing is that I want to catch any exception…
tincho87
  • 349
  • 1
  • 4
  • 12
4
votes
3 answers

MediatR Multiple Pipeline Behaviors

Helllo I already use this pattern of Mediator CQRS with Pipeline Behavior for a while, but just now i'm facing a issue where the generic implementation of TResponse and TRequest are not enough. So i'm trying to understand if having two separate…
Lincoln Teixeira
  • 145
  • 2
  • 10
4
votes
2 answers

System.ObjectDisposedException: 'Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope

I have an async controller and I am trying to call two different Async functions from it. like this public async void Approvefiles(string[] data) { var response = await _mediator.Send(new persons.Query(data)); await…
None
  • 5,582
  • 21
  • 85
  • 170
4
votes
2 answers

Return response with errors in MediatR pipeline behavior

I'm new to MediatR, trying to make request validation using pipeline behavior, all the examples that I came across were throwing ValidationException if any errors happening. below code is an example of validation pipeline: public class…
Vamp808
  • 51
  • 1
  • 7
4
votes
1 answer

Resequencer for MediatR INotificationHandler - can't use IPipelineBehavior

I have seen MediatR IPipelineBehavior and looking to use a resequencer for event bus notifications to be put in order. The aspect orientated angle is very interesting/useful to split up functionality into separate handlers. I…
morleyc
  • 2,169
  • 10
  • 48
  • 108
4
votes
1 answer

How to avoid code duplication in MediatR request handlers?

I am playing around with CQRS and the MediatR library, trying to learn some of the best practices. One problem I have is code duplication in Command/Query handlers. I would like to know what is the best way to share logic between…
Gur Galler
  • 820
  • 9
  • 21
4
votes
2 answers

When executing API method using MediatR, getting an error

It is my 1st time implementing Mediator but now I get the following error when calling API method: ERROR {"error":"Enumerator failed to…
Gericke
  • 2,109
  • 9
  • 42
  • 71
4
votes
1 answer

How can we use 'yield return' to return IAsyncEnumerable from MediatR Request handler?

I have a query class that implements Mediatr.IRequest like below: public class ExportDataQuery : IRequest> {} The query handler has been implemented as follows: public class ExportDataQueryHandler :…
4
votes
3 answers

HTTP request in pending status until MediatR notifications executed

var response = SaveOrderInDB(); OrderCreatedEvent orderCreatedEvent = new OrderCreatedEvent(x, y, z); _requestRouter.Publish(orderCreatedEvent); return response; By MediatR docs the notifications is "Fire and forget" feature. I do not…
Nick
  • 423
  • 4
  • 19
4
votes
0 answers

Communication between modules - MediatR or Interface/Fasade?

I'm involved in fully modular monolithic application project. We use MediatR like Jimmy describes in this article: Dealing with Duplication in MediatR Handlers. Exactly this: I want MediatR to serve as the outermost window into the actual…
dariol
  • 1,959
  • 17
  • 26
4
votes
1 answer

Moving MediatR from a MVC project to Razor Pages. Cannot get basic syntax to work

The working MVC version is public class StatCategoriesController : BaseController { [HttpGet] public async Task>> GetStatCategoryPreview([FromQuery] GetStatCategoryPreviewQuery query) { …
punkouter
  • 5,170
  • 15
  • 71
  • 116
4
votes
1 answer

MediatR NotificationHandler fire and forget

How can I make my MediatR notification handler fire and forget? My sample code: public class BackupDatabase : INotification {} public class BackupDatabaseNotificationHandler : INotificationHandler { public async Task…
4
votes
0 answers

How to inject autofac dependency in asp.net core 2.0 IHostedService

I am developing asp.net core 2.0 webapi and want a background task to process message from kafka message bus. I read some document realted to IHostedService and created a custom Background service. I am implementing CQRS with MediatR. I have…
Mukil Deepthi
  • 6,072
  • 13
  • 71
  • 156