Composition handlers receive the fullDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ServiceComposer/ServiceComposer.AspNetCore/llms.txt
Use this file to discover all available pages before exploring further.
HttpRequest object and can access incoming data in several ways — from reading the raw request body as a stream, to leveraging ASP.NET Core’s model binding infrastructure for strongly typed binding. ServiceComposer also provides declarative Bind* attributes that let you declare what you need without writing imperative binding code, and an experimental named-arguments API for retrieving bound values from the composition context.
Raw access to request data
The simplest approach is to read directly from theHttpRequest. This requires no additional configuration.
- Request Body
- Route Data
Read the body as a string and parse it manually:Setting
Position = 0 is required because ServiceComposer enables body buffering so that multiple handlers can read the same body.ASP.NET Core model binding
Available since v1.9.0 To use ASP.NET Core’s model binding engine you must register MVC components. AddAddControllers() (or any other MVC variant) alongside AddViewModelComposition():
If your application already uses MVC, Razor Pages, or controllers, model binding is already available and no additional configuration is needed.
Defining binding models
Define a body model and a composite request model using the standard ASP.NET binding attributes:[FromRoute] or [FromQuery] must match the route parameter names or query string key names. The class names themselves are irrelevant.
Bind<T> — bind and use immediately
Call request.Bind<T>() to bind the incoming request to a model in one step:
TryBind<T> — bind with model state access
Available since v2.2.0
TryBind<T> returns a tuple with the bound model, a flag indicating whether the model was set, and the ModelStateDictionary for inspecting binding errors:
isModelSet boolean distinguishes between a model binder that found no value and one that explicitly bound null.
Declarative model binding
Available since v4.1.0 Instead of callingBind/TryBind imperatively, you can declare the models you need directly on the handler method using Bind* attributes. ServiceComposer resolves them before invoking Handle and makes the results available via the arguments API:
Available binding attributes
BindFromBody<T>
Binds type
T from the request body payload.BindFromRoute<T>
Binds type
T from the route value identified by routeValueKey.BindFromQuery<T>
Binds type
T from the query string parameter identified by queryParameterName.BindFromForm<T>
Binds type
T from the form fields collection. If formFieldName is specified, only that field is used as the binding source.BindFromServices<T>
Resolves type
T from the DI container. The parameterName argument identifies the argument in the composition context.Bind<T>
Binds type
T from multiple sources. Each property on T can specify its own source using [FromBody], [FromRoute], etc.Accessing bound values — the arguments API
Experimental API (SC0001) Once models are declared withBind* attributes, retrieve them from the composition context using GetArguments:
GetArguments(this) scopes the lookup to the calling handler. Only instances of ICompositionRequestsHandler, ICompositionEventsSubscriber, and ICompositionEventsHandler<T> can be passed as the owner argument.
Contract-less handlers and model binding
When using contract-less composition handlers, model binding is declared through method parameter attributes and the source generator emits the correctBind* attributes automatically. [FromServices] parameters are resolved from DI; other parameters follow standard ASP.NET binding conventions:
[BindFromRoute<int>("id")] and [BindFromServices<IMyService>("myService")] automatically, keeping the user-written class free of infrastructure concerns.