generated from dailydevops/template-dotnet
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
type:featureIndicates a new feature or enhancement to be added.Indicates a new feature or enhancement to be added.
Description
User Story
As a developer building ASP.NET Core Minimal API applications with Pulse, I want IEndpointRouteBuilder extension methods that map mediator commands and queries directly to HTTP endpoints, so that I can eliminate the boilerplate of writing controller actions or endpoint lambdas that only forward to IMediator.
Background
A common pattern in Minimal API projects is:
app.MapPost("/orders", async (CreateOrderCommand cmd, IMediator mediator, CancellationToken ct) =>
Results.Ok(await mediator.SendAsync<CreateOrderCommand, OrderCreated>(cmd, ct)));This pattern is repeated for every command and query. An IEndpointRouteBuilder integration generates these routes from CQRS message types, following conventions, and keeps the registration layer concise.
Requirements
- Provide a new NuGet package
NetEvolve.Pulse.AspNetCoretargetingnet8.0,net9.0,net10.0. - Define the following extension methods on
IEndpointRouteBuilder:// Map a command to a POST endpoint RouteHandlerBuilder MapCommand<TCommand, TResponse>( this IEndpointRouteBuilder endpoints, string pattern) where TCommand : ICommand<TResponse>; // Map a void command to a POST endpoint RouteHandlerBuilder MapCommand<TCommand>( this IEndpointRouteBuilder endpoints, string pattern) where TCommand : ICommand<Void>; // Map a query to a GET endpoint RouteHandlerBuilder MapQuery<TQuery, TResponse>( this IEndpointRouteBuilder endpoints, string pattern) where TQuery : IQuery<TResponse>;
- Each generated endpoint:
- Binds the request body (for commands) or query string / route parameters (for queries) using the default Minimal API model binding.
- Calls the corresponding
IMediatormethod (SendAsyncorQueryAsync). - Returns
Results.Ok(response)on success. - Returns
Results.NoContent()for void commands (ICommand<Void>). - Propagates
CancellationTokenfrom the HTTP request.
- All registered endpoints must be compatible with
Microsoft.AspNetCore.OpenApi(WithOpenApi()chainable). - The package must reference
NetEvolve.Pulse.ExtensibilityandMicrosoft.AspNetCore.Http.Abstractions. - No dependency on
NetEvolve.Pulseitself — the mediator is resolved from DI at request time.
Acceptance Criteria
-
NetEvolve.Pulse.AspNetCorepackage builds on all three target frameworks. -
MapCommand<TCommand, TResponse>registers aPOSTendpoint that dispatches viaIMediator.SendAsync. -
MapCommand<TCommand>registers aPOSTendpoint that returns204 No Contentfor void commands. -
MapQuery<TQuery, TResponse>registers aGETendpoint that dispatches viaIMediator.QueryAsync. - Endpoints correctly propagate
CancellationToken. - Generated endpoints are compatible with
WithOpenApi()and produce correct OpenAPI metadata. - Unit tests verify route registration and HTTP result types.
- Integration tests verify end-to-end HTTP dispatch through
WebApplicationFactory<T>. - XML documentation is provided for all public members.
Out of Scope
- MVC controller integration (action filters,
IActionResultreturn types). - Event publishing endpoints.
- Streaming query endpoints (follow-up after feat: Streaming query support via
IStreamQuery<TResponse>andIAsyncEnumerable#128). - Authentication / authorization attributes on generated endpoints — callers chain
.RequireAuthorization(). - Automatic route convention derivation from command/query type names.
Reactions are currently unavailable
Metadata
Metadata
Labels
type:featureIndicates a new feature or enhancement to be added.Indicates a new feature or enhancement to be added.