Skip to main content

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.

ServiceComposer is an ASP.NET Core ViewModel Composition Gateway. It solves the challenge of assembling a unified API response from data owned by multiple independent services. Each service registers a small composition handler that contributes its slice of data; ServiceComposer runs all handlers in parallel and returns a single merged JSON object to the caller — with no service knowing about any other.

Introduction

Understand the ViewModel Composition pattern and when to use ServiceComposer.

Quickstart

Install, configure, and write your first composition handler in minutes.

Composition Handlers

Learn how handlers from different services contribute data to the same route.

Scatter/Gather

Fan out HTTP requests to downstream services and merge the results automatically.

Events

Coordinate between handlers within a single request using in-process events.

API Reference

Browse the full public API surface — interfaces, extensions, and options.

How it works

ServiceComposer integrates with the ASP.NET Core endpoint routing pipeline. You configure it once in Program.cs, then let each service define its own handler class library.
1

Install the NuGet package

Add ServiceComposer.AspNetCore to your ASP.NET Core gateway project.
dotnet add package ServiceComposer.AspNetCore
2

Register and map composition handlers

Call AddViewModelComposition() and MapCompositionHandlers() in Program.cs.
Program.cs
var builder = WebApplication.CreateBuilder();
builder.Services.AddRouting();
builder.Services.AddViewModelComposition();

var app = builder.Build();
app.MapCompositionHandlers();
app.Run();
3

Write a composition handler in each service

Implement ICompositionRequestsHandler and decorate it with an HTTP routing attribute.
SalesProductInfo.cs
public class SalesProductInfo : ICompositionRequestsHandler
{
    [HttpGet("/product/{id}")]
    public Task Handle(HttpRequest request)
    {
        var vm = request.GetComposedResponseModel();
        vm.ProductPrice = 100;
        return Task.CompletedTask;
    }
}
4

Reference handler assemblies from the gateway

Add project or NuGet references to each handler library. ServiceComposer’s assembly scanner discovers handlers automatically at startup.

Key capabilities

Parallel execution

All handlers for a route run concurrently via Task.WhenAll, keeping latency low even as the number of services grows.

Zero service coupling

Handlers never import each other. Each service evolves its handler independently.

Strongly typed view models

Replace dynamic objects with a concrete typed view model using IViewModelFactory.

Model binding

Use ASP.NET Core’s built-in model binding to access body, route, query, and form values inside handlers.

Composition filters

Intercept and short-circuit composition requests before they reach specific handlers.

OpenTelemetry

Built-in ActivitySource tracing for both ViewModel Composition and Scatter/Gather pipelines.

Build docs developers (and LLMs) love