# Corfedo Troupe

> Build a .NET host from components that declare what they register, require and configure.

Wojciech Wentland · https://blog.wentland.io/projects/corfedo-troupe/

Status: alpha · License: Apache-2.0 · Source: https://github.com/corfedo/corfedo-troupe

In a large application, `Program.cs` can grow into hundreds of registrations nobody owns, and a missing configuration
section shows up only when a request hits it. Troupe builds the host from components that declare what they
register, what they require and which configuration they read. It records the owner of every registration, so a
misconfigured host fails at startup with a diagnostic that names the components involved.

```csharp
public sealed class WorkerSettings : IComponent
{
    public void Compose(IComponentBuilder component) =>
        component.Options<HeartbeatOptions, HeartbeatValidator>("Worker");
}
```

If the `Worker` section is missing, the host doesn't start. Composition fails with `TRP005`, which names
`WorkerSettings` and the missing section.

## One executable, several deployments

A role is a workload; a profile is an exact set of roles. The same declarations run as one combined process or split
across several, selected with `--profile` at startup:

```csharp
definition.Role<OrdersRole>().Role<NotificationsRole>()
    .Profile("orders", "orders")
    .Profile("notifications", "notifications")
    .Profile("combined", "orders", "notifications");
```

At runtime a caller can ask whether an owner is composed in this process, and call it directly or over the
transport the application already uses, such as HTTP, gRPC or a queue.

## A manifest you can query

Every process can say what it composes, who registered each service, who reads each configuration section and who
contributed to third-party builders such as Wolverine's options. Tests use the same manifest to verify every declared
profile against a real host, and application rules can check policy against it.

## Status

Alpha: the API can still change. The Corfedo platform runs on it, as one executable with roles such as web, API,
MCP, worker and AI executor. Install it from NuGet with `dotnet add package Corfedo.Troupe`; add
`Corfedo.Troupe.AspNetCore` for web hosts and `Corfedo.Troupe.Testing` for profile verification. The source and
examples are [on GitHub](https://github.com/corfedo/corfedo-troupe).
