ServiceComposer.AspNetCore

Composition over controllers

ServiceComposer can be used to enhance a MVC web application by adding composition support to Controllers. ServiceComposer can be configured to use a technique called “Composition over controllers”:

builder.Services.AddViewModelComposition(options =>
{
    options.EnableCompositionOverControllers();
});

snippet source | anchor

Once composition over controllers is enabled, ServiceComposer will inject a MVC filter to intercept all controllers invocations. If a route matches a regular controller and a set of composition handlers ServiceComposer will invoke the matching handlers after the controller and before the view is rendered.

Composition over controllers supports both regular composition handlers (classes implementing ICompositionRequestsHandler) and contract-less composition handlers, including full model binding support for both.

Composition over controllers can be used as a templating engine leveraging the excellent Razor engine. Optionally, it can be used to add ViewModel Composition support to MVC web application without introducing a separate composition gateway.