|
using MediatR; |
|
using Microsoft.AspNetCore.Builder; |
|
using Microsoft.AspNetCore.Http; |
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
namespace MediatRPC; |
|
|
|
public static class WebApplicationExtensions |
|
{ |
|
public static void MapGet<TRequest, TResponse>(this WebApplication app, string route) where TRequest: IRequest<TResponse> |
|
=> app.MapGet(route, ([FromServices] IMediator mediator, [AsParameters] TRequest request) => mediator.Send(request)); |
|
|
|
public static void MapGet<TRequest>(this WebApplication app, string route) where TRequest: IRequest |
|
=> app.MapGet(route, ([FromServices] IMediator mediator, [AsParameters] TRequest request) => mediator.Send(request)); |
|
|
|
public static void MapPost<TRequest, TResponse>(this WebApplication app, string route) where TRequest: IRequest<TResponse> |
|
=> app.MapPost(route, ([FromServices] IMediator mediator, [FromBody] TRequest request) => mediator.Send(request)); |
|
|
|
public static void MapPost<TRequest>(this WebApplication app, string route) where TRequest: IRequest |
|
=> app.MapPost(route, ([FromServices] IMediator mediator, [FromBody] TRequest request) => mediator.Send(request)); |
|
|
|
// the following are not typically used in RPC-over-REST, but they're included in case you want them, anyway: |
|
/* |
|
public static void MapPut<TRequest, TResponse>(this WebApplication app, string route) where TRequest: IRequest<TResponse> |
|
=> app.MapPut(route, ([FromServices] IMediator mediator, [FromBody] TRequest request) => mediator.Send(request)); |
|
|
|
public static void MapPut<TRequest>(this WebApplication app, string route) where TRequest: IRequest |
|
=> app.MapPut(route, ([FromServices] IMediator mediator, [FromBody] TRequest request) => mediator.Send(request)); |
|
|
|
public static void MapPatch<TRequest>(this WebApplication app, string route) where TRequest: IRequest |
|
=> app.MapPatch(route, ([FromServices] IMediator mediator, [FromBody] TRequest request) => mediator.Send(request)); |
|
|
|
public static void MapPatch<TRequest, TResponse>(this WebApplication app, string route) where TRequest: IRequest<TResponse> |
|
=> app.MapPatch(route, ([FromServices] IMediator mediator, [FromBody] TRequest request) => mediator.Send(request)); |
|
|
|
public static void MapDelete<TRequest, TResponse>(this WebApplication app, string route) where TRequest: IRequest<TResponse> |
|
=> app.MapDelete(route, ([FromServices] IMediator mediator, [FromBody] TRequest request) => mediator.Send(request)); |
|
|
|
public static void MapDelete<TRequest>(this WebApplication app, string route) where TRequest: IRequest |
|
=> app.MapDelete(route, ([FromServices] IMediator mediator, [FromBody] TRequest request) => mediator.Send(request)); |
|
*/ |
|
} |