Model-Bound Operations
Arc supports minimal API-style endpoints for commands and queries, called model-bound operations. These endpoints are registered automatically by the Arc infrastructure and follow a convention-based naming scheme (Execute<TypeName>).
Because model-bound endpoints do not use traditional controller actions, the standard CommandResultOperationTransformer and QueryResultOperationTransformer transformers do not apply to them. The ModelBound.CommandOperationTransformer and ModelBound.QueryOperationTransformer fill this gap.
Registration
Section titled “Registration”Model-bound transformers are included automatically when you call AddConcepts():
builder.Services.AddOpenApi(options => options.AddConcepts());They can also be registered independently:
builder.Services.AddOpenApi(options => options.AddModelBoundOperationTransformers());Command operations
Section titled “Command operations”The ModelBound.CommandOperationTransformer matches operations whose operationId starts with Execute and resolves the command type from the registered ICommandHandlerProviders.
For matched operations it:
- Sets the
requestBodyto a schema of the command type. - Attempts to infer a
CommandResult/CommandResult<T>200 response schema from the registered handler adapter’sHandlemethod. - Adds 400, 403, and 500 error response schemas.
Command type illustration (application persistence is deliberately outside this example):
using Cratis.Arc.Commands.ModelBound;
[Command]public record EchoInvoiceId(Guid Id){ public Guid Handle() => Id;}Query operations
Section titled “Query operations”The ModelBound.QueryOperationTransformer attempts to match operations whose operationId starts with Execute against registered IQueryPerformerProviders.
Current limitation: it compares the suffix to performer.Name, while the runtime GET mapper uses performer.FullyQualifiedName in endpoint names. A normal model-bound method name and its fully qualified name differ, so this transformer can miss the generated operation. The additional HTTP QUERY endpoint is excluded from API description by its request reader. Inspect the generated document rather than assuming all query arguments and result schemas below were applied.
For matched operations it:
- Adds each query parameter from the performer’s parameter list as a query string parameter, currently with
Required = falseeven when runtime binding requires it. - Adds paging and sorting parameters when
IQueryPerformer.SupportsPagingistrue. - Sets the 200 response schema to
QueryResult. - Adds 400, 403, and 500 error response schemas.
Pagination and sorting parameters
Section titled “Pagination and sorting parameters”For query performers that support paging, the following query parameters are added:
| Parameter | Type | Description |
|---|---|---|
sortby | string | Field name to sort by |
sortDirection | string (asc | desc) | Sort direction |
pageSize | integer | Number of items per page |
page | integer | Page number (0-based) |