Skip to content

Aspire ResourceKit

Preview Aspire ResourceKit Reviewed 2026-09-14 purview-dev/aspire-resourcekit apphost aspire cloud-native code-generation csharp developer-tools distributed-systems dotnet dotnet-aspire integration-testing resource-management roslyn source-generators testing

NuGet version Release

Purview.Aspire.ResourceKit is a source-generator-powered framework for structuring .NET Aspire AppHost resource composition as strongly typed, test-friendly classes.

If your AppHost is getting bigger, this helps you keep resource setup maintainable and discoverable by moving composition into focused resource classes and generating the plumbing for you.

  • Cleaner AppHost code with resource logic split into dedicated classes.
  • Strong typing + IntelliSense instead of stringly-typed setup.
  • Generated wiring for host/resource options and registration.
  • Predictable lifecycle (Build then Configure) for inter-resource dependencies.
  • Testability with options overrides and isolated resource composition.
using Aspire.Hosting;
using Aspire.Hosting.ApplicationModel;
using Purview.Aspire.ResourceKit;
[HostKit]
partial class ShopHostKit;
[ResourceDefinition<ProjectResource>("api")]
partial class ApiResourceKit
{
protected override IResourceBuilder<ProjectResource> BuildResource(IDistributedApplicationBuilder builder)
=> builder.AddProject<Projects.Example_Service>(Name);
}
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAspireResourceKit();

The extension method name is generated from your host metadata; in this repository sample it is AddAspireResourceKit().

Lifecycle mental model (early cheat sheet)

Section titled “Lifecycle mental model (early cheat sheet)”

ResourceKit has two layers of lifecycle methods:

  • Build / BuildResource(...): construct this resource (AddProject, AddRedis, etc.).
  • Configure / ConfigureResource(): attach resources to each other (references, bindings, cross-resource wiring).

Enablement is evaluated before resource construction:

  • IsEnabled is the persisted toggle (typically from generated options).
  • IsResourceEnabled(builder) is the runtime hook used by Build to decide whether this resource should run now.
  • If it evaluates to false, both BuildResource(...) and ConfigureResource() are skipped for that resource.

Use IsResourceEnabled(builder) when enablement depends on runtime state (environment, config, publish mode, etc.), not just static options.

From your [HostKit] and [ResourceDefinition] declarations, ResourceKit generates:

  • a host resource base class,
  • resource properties on the host,
  • host + per-resource options (when enabled),
  • an AppHost extension method to build/configure/register your host kit.
  • src/src/ResourceKit — runtime package source.
  • src/src/SourceGeneration — Roslyn source generator.
  • src/src/Example.* — sample Aspire applications.
  • src/tests/* — unit and integration tests.