ServiceComposer lets any assembly that participates in composition configure its own options at startup — no changes to the host application’sDocumentation 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.
Program.cs required. The assembly scanner discovers every type that implements IViewModelCompositionOptionsCustomization and calls its Customize method before the application begins handling requests, making this pattern ideal for self-contained service packages and plugins.
The IViewModelCompositionOptionsCustomization interface
The contract is a single method:Basic usage
Place a class that implements the interface anywhere in a class-library assembly. When the host callsAddViewModelComposition(), the scanner finds it automatically and invokes Customize.
Accessing configuration
ViewModelCompositionOptions.Configuration is null by default. If you attempt to read it without first supplying an IConfiguration instance, ServiceComposer throws an ArgumentException. To enable it, pass the configuration object when registering ServiceComposer:
Custom DI registration with AddServicesConfigurationHandler
By default, ServiceComposer registers every discovered composition handler with its ownAddTransient call. AddServicesConfigurationHandler lets you override that behaviour for a specific handler type — for example, to register it as a singleton, supply constructor arguments, or use a factory method.
Only one
AddServicesConfigurationHandler can be registered per type. Registering a second handler for the same type throws a NotSupportedException.Custom type filtering with AddTypesRegistrationHandler
AddTypesRegistrationHandler gives you full control over which types the scanner should pick up and how they should be registered. You supply a predicate that receives each candidate Type, and a registration callback that receives the matching types as a collection.
Define the registration callback
Write the callback that registers the matched types into the DI container:
How discovery works
Host calls AddViewModelComposition()
The host application calls
builder.Services.AddViewModelComposition(), optionally passing an IConfiguration instance.Assembly scanner runs
ServiceComposer scans all loaded assemblies for types that implement
IViewModelCompositionOptionsCustomization.Customize is invoked
Each discovered type is instantiated (without DI) and its
Customize(ViewModelCompositionOptions) method is called, allowing the library to configure assembly filters, DI overrides, or type registration handlers.