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

Using MediatR is it possible to create a generic RequestExceptionHandler for any and all requests?

I created a request exception handler with known types as below and the exception is handled. The only examples I found are doing it this way. using MediatR.Pipeline; using Microsoft.Extensions.Logging; using…
DaveG
  • 121
  • 1
  • 6
5
votes
1 answer

Unable to resolve Fluent Validation using MediatR without StructureMap

Trying to inject Fluent Validation in .Net Core 3.1 micro service with MediatR without Structure Map. Added Below Nuget Packages:
Rahul
  • 63
  • 1
  • 9
5
votes
1 answer

Unit testing validation through MediatR PipelineBehavior

I'm using FluentValidation and MediatR PipelineBehavior to validate the CQRS requests. How should I test this behavior in my unit tests? Use the test extensions of FluentValidation and I test only the…
5
votes
1 answer

How to cancel the query sent by MediatR?

I'm using MediatR in .Net core 3.1 Blazor application. The following are the query and its handler. public class GetSaleQuery : IRequest { public GetSaleQuery(string id) { Id = id; } public string Id { get;…
ca9163d9
  • 27,283
  • 64
  • 210
  • 413
5
votes
1 answer

.NET Core console app Mediatr command handler doesn't get called

I'm facing a problem that Mediatr command handler is not called. I have the following solution structure. Project.sln -> Application layer (.NET standard class library) -> Jobs (.NET standard class library) -> Job Server (.NET Core console app) The…
user3646017
  • 51
  • 1
  • 1
  • 5
5
votes
1 answer

Unity DI Container RegisterType method breaking changes from v5.8.x to v5.9.x

I was using Unity DI Container v5.8.4 on my .NET Core 2.1 project and I needed to register Mediator object and I was using the configuration suggested here. Now I have updated to v5.9.4 and I have an error about RegisterType method…
Cheshire Cat
  • 1,941
  • 6
  • 36
  • 69
5
votes
2 answers

Nested queries with MediatR/CQRS

I'm just wondering if the design I will be trying to implement is valid CQRS. I'm going to have a query handler that itself will send more queries to other sub-handlers. Its main task is going to aggregate results from multiple services. Is this ok…
mbudnik
  • 2,087
  • 15
  • 34
5
votes
3 answers

Validation in a Mediatr behaviour pipeline

I am using the Mediatr 4 with my web api 2 project. Together with FluentValidation and Unity I have been adding a pipeline behaviour to validate my requests. public class ValidationBehavior : IPipelineBehavior
DevOverflow
  • 491
  • 1
  • 5
  • 16
5
votes
2 answers

Executing MediatR PreProcessor Only for Specific Interface Types (Commands)

[NOTE: This is a "replacement" question. The first one was based on my main project's code so I've redone the question with code from a single-purpose project that illustrates the principle more cleanly. The question remains the same, just better…
platypusjh
  • 667
  • 1
  • 7
  • 16
5
votes
1 answer

Dependency Scope Issues with MediatR and SimpleInjector

I've been experimenting with the mediator pattern and CQRS using the MediatR library in a WinForms application that uses the Entity Framework for data access. The application is used in a batch manufacturing plant, and allows users to see a list of…
Brett Wolfington
  • 6,587
  • 4
  • 32
  • 51
5
votes
1 answer

How can I decorate all my bindings implementing a specific interface in Ninject

I'm using Jimmy Bogard's Mediatr and trying to use the pipleine example here my problem is that although I can get all my closing generic types like so kernel.Bind( x => x.FromAssemblyContaining() …
Kev Hunter
  • 2,565
  • 4
  • 25
  • 39
4
votes
1 answer

No service for type 'MediatR.IRequestHandler' has been registred .net 6

[![enter image description here][1]][1]Im using asp.net core .net 6 and MediatR 12.0.1 and i'm not using on purpose MediatR.Extensions.Microsoft.DependencyInjection which is deprecated. In my Program.cs file i have: builder.Services.AddMediatR(cfg…
mbahojlo
  • 95
  • 1
  • 10
4
votes
3 answers

MediatR conventions in CQRS

I am using MediatR and CQRS in a real project using the Clean Architecture principles. Is it correct to: Call Command from NotificationHandler? Call Command in Command? Call Query in Command? If you have some resource for these principle,…
Ahmad
  • 49
  • 4
4
votes
1 answer

Using MediatR in a console application

Does anyone know how to implement MediatR in a console application, to call a handler function using the _mediatr.Send(obj) syntax. I'm using the .Net 6 framework. Thanks for the help.
bflow1
  • 49
  • 1
  • 9
4
votes
1 answer

MediatR Pipeline Priority

How can I set the priority of PipelineBehaviors? I have 3 pipeline. I want to execute AuthorizationPipeline first. If the AuthorizationPipeline throws any SecurityException, I am not going to execute other pipelines.
Abdulkadir KG
  • 83
  • 1
  • 8