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.
ICompositionRequestFilter introduces a middleware-style pipeline that wraps individual composition handlers. Filters allow you to execute logic before and after a handler runs — for example, to perform authorization checks, enrich request context, measure execution time, or short-circuit a request with an error response. The filter pipeline is structurally identical to ASP.NET Core’s endpoint filter pipeline.
Two implementation strategies are available:
ICompositionRequestFilter— a class that implements the filter and is associated with a handler viaICompositionRequestFilter<T>or attribute decoration.CompositionRequestFilterAttribute— an abstract attribute that you derive from, allowing filters to be applied directly as class/method attributes.
Namespace
ServiceComposer.AspNetCore
Interface definitions
ICompositionRequestFilter
ICompositionRequestFilter<T>
ICompositionRequestFilter<T> targets a specific handler type T. When you implement this interface, ServiceComposer automatically applies the filter to every composition endpoint served by handler T. This is the preferred approach for associating reusable filters with handlers without modifying the handler class.
CompositionRequestFilterAttribute
CompositionRequestFilterAttribute is an abstract base class that combines Attribute and ICompositionRequestFilter. Derive from it to create an attribute that can be applied directly to a handler class or its Handle method.
CompositionRequestFilterContext
Passed to everyInvokeAsync call. Provides access to the current HttpContext.
The current ASP.NET Core
HttpContext. Use it to inspect or modify the request, access services from the DI container, or write to the response.CompositionRequestFilterDelegate
The delegate type that represents the remainder of the filter pipeline (or the handler itself):next(context) to pass control to the next filter or to the handler. Returning without calling next short-circuits the pipeline and prevents the handler from executing.
Methods
InvokeAsync
Contains the
HttpContext for the current composition request. Inspect or mutate request/response state here.A delegate that invokes the next filter in the pipeline, or the handler if no more filters remain. You must
await (or return) the result of next(context) to allow downstream execution to proceed. To short-circuit, return a result without calling next.ValueTask<object> — the composition result produced by the remainder of the pipeline.
Applying filters
Via attribute on the handler
Derive fromCompositionRequestFilterAttribute and apply the attribute to the handler class or Handle method:
Via typed ICompositionRequestFilter<T>
ImplementICompositionRequestFilter<T> to associate a filter with handler type T without modifying the handler:
When using
ICompositionRequestFilter<T>, the filter is automatically applied to all endpoints handled by T. No attribute decoration on the handler is needed.Short-circuiting the pipeline
Return a result without callingnext to prevent the handler (and any subsequent filters) from executing:
DI registration
ICompositionRequestFilter<T> implementations are discovered automatically by the assembly scanner and registered as transient services. CompositionRequestFilterAttribute subclasses do not need separate DI registration — they are instantiated by the attribute infrastructure.
Enable scanning with: