Documentation 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.
ServiceCollectionExtensions is the entry point for adding ServiceComposer to an ASP.NET Core application. Call one of its AddViewModelComposition overloads inside ConfigureServices (or the WebApplicationBuilder.Services equivalent) to register the composition engine and all its internal services. Once the DI container is built, the companion extension methods on HttpRequest give composition handlers convenient access to the assembled ViewModel, the current composition context, and MVC model binding.
ServiceCollectionExtensions
Static class in theServiceComposer.AspNetCore namespace.
AddViewModelComposition
Overload 1 — defaults onlyThe application service collection.
The application configuration root. Pass this when you need to read
IConfiguration
inside a ViewModelCompositionOptions customization or custom handler. Accessing
ViewModelCompositionOptions.Configuration without supplying this value throws an exception.config with a ViewModelCompositionOptions instance, allowing fine-grained control over assembly scanning, serialization, write support, and handler registration.
The application service collection.
Delegate that receives a
ViewModelCompositionOptions to configure the pipeline.The application configuration root. Required if
ViewModelCompositionOptions.Configuration
will be accessed at runtime.HttpRequestExtensions
Static class in theServiceComposer.AspNetCore namespace. These extension methods are called from within composition handlers after the ViewModel has been assembled.
GetComposedResponseModel
HttpContext.Items as a dynamic object. Use this when the ViewModel type is not known statically.
The current HTTP request.
dynamic — the composed ViewModel, or null if none has been set yet.
GetComposedResponseModel<T>
T. Throws InvalidCastException if the stored ViewModel cannot be cast, which typically means the registered IViewModelFactory does not produce instances of T.
The current HTTP request.
T — the expected ViewModel type; must be a reference type.
Returns T — the strongly typed ViewModel.
GetCompositionContext
ICompositionContext for the current request, which exposes the request ID and event-raising capabilities.
The current HTTP request.
ICompositionContext.
SetActionResult
ActionResult that ServiceComposer will use as the HTTP response instead of the serialized ViewModel. Useful for returning redirect or error responses from a handler.
The current HTTP request.
The
ActionResult to return. Only the first call per request takes effect.HttpRequestModelBinderExtension
Static class in theServiceComposer.AspNetCore namespace. Provides MVC model binding inside composition handlers without requiring a controller.
Bind<T>
T using the MVC model binding pipeline. Returns the bound model directly.
The current HTTP request.
T — the model type. Must have a public parameterless constructor.
Returns Task<T> — the bound model.
TryBind<T>
T and returns a tuple with the model, a flag indicating whether binding succeeded, and the ModelStateDictionary for validation error inspection.
The current HTTP request.
T — the model type. Must have a public parameterless constructor.
Returns Task<(T Model, bool IsModelSet, ModelStateDictionary ModelState)>.
Note: Model binding requires MVC services to be registered. Callservices.AddControllers()(or one of its variants) beforeAddViewModelComposition.