Skip to content

vip32/MediatR.Commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quality Gate Status NuGet

MediatR.Commands

A simple commands & queries extension for the great MediatR library.

Usage

Startup.cs::ConfigureServices()

    services.AddMediatR(new[] { typeof(WeatherForecastsQuery).Assembly });
    services.AddTransient(typeof(IPipelineBehavior<,>), typeof(DummyQueryBehavior<,>));

Startup.cs::Configure()

TODO

Controller

    [ApiController]
    [Route("weatherforecasts")]
    public class WeatherForecastController : ControllerBase
    {
        ...

        [HttpGet]
        public async Task<IEnumerable<WeatherForecastResponse>> Get()
        {
            return await this.mediator.Send(new WeatherForecastsQuery()).ConfigureAwait(false);
        }
    }

or without Controllers see Startup.cs

services.AddCommandEndpoints(); // ConfigureServices

app.UseEndpoints(endpoints => // Configure
{
  ... 

  endpoints.MapGet<UserFindAllQuery>(
    "/users", "User");

  endpoints.MapGet<UserFindByIdQuery>(
    "/users/{userId}", "User");

  ...
}