Skip to content

About

Source-generator-powered resource kits for .NET Aspire: turn AppHost resource composition into strongly typed, testable classes with generated host wiring, typed options, and enablement toggles for local, test, and publish modes.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

178 Commits

Folders and files

Repository files navigation

Aspire Resource Kit

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.

Important

Requires .NET 10. The package ships net10.0 and net11.0 assets — there is no net8.0 or net9.0 asset. A .NET 10 AppHost resolves the net10.0 asset; a .NET 11 AppHost resolves the net11.0 asset. See Versioning and compatibility.

For what changed, see the changelog and release notes.

Tip

Lifecycle quick links

Why teams use it

  • 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.
  • Parent/child resource hierarchies for VNETs and subnets, SQL servers and databases, Service Bus namespaces and topics/queues/subscriptions, or storage accounts and containers (issue #57).
  • Predictable lifecycle (Build then Configure) for inter-resource dependencies.
  • Hierarchical kits so a parent resource can own child kits, with typed Parent access, parent-first build ordering, inherited enablement, and nested options.
  • Testability with options overrides and isolated resource composition.

Quick example

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().

Tip

Agent skills for your coding agent

This repository authors Agent Skills describing ResourceKit — declaring a [HostKit] and resource kits, the generated options and run modes, test fixtures, and what each SG00xx diagnostic means.

They are not shipped in the NuGet package, and nothing copies them into your repository on build. The skills CLI clones the git repository and installs them into your agent's own skill directory:

npx skills add purview-dev/aspire-resourcekit

Append #<ref> to pin a commit or tag. The CLI records the installed set in skills-lock.json, so it can be restored later with npx skills experimental_install.

Lifecycle mental model

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:

  • Mode selects which AppHost execution a kit participates in (All, LocalDevelopment, Run, Publish). It is configured through the generated options and can be declared on [HostKit]/[ResourceDefinition].
  • IsEnabled is the persisted toggle (typically from generated options) and the single member consumers need to check.
  • IsResourceEnabled(builder) is the runtime hook used by Build to decide whether this resource should run now.
  • If any gate excludes the resource, both BuildResource(...) and ConfigureResource() are skipped for that resource.
  • A child kit is also disabled when any ancestor is disabled; an ancestor-disabled kit never runs a descendant's IsResourceEnabled hook.

Use Mode for publish-only or local-development-only resources, and IsResourceEnabled(builder) when enablement depends on runtime state beyond an execution mode (environment probes, dynamic configuration).

What gets generated

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

  • a host resource base class,
  • typed parent/child properties and constructors for hierarchical kits,
  • host + per-resource options (when enabled), including nested child options,
  • typed resource groups ([ResourceGroup], [InGroup<TGroup>]) that switch sets of resources on or off and nest them in the dashboard,
  • named dashboard URLs ([ResourceUrl], [EndpointUrl]) that options can override,
  • an AppHost extension method to build/configure/register your host kit.

Documentation

Repository layout

  • src/src/ResourceKit — runtime package source.
  • src/src/SourceGeneration — Roslyn source generator.
  • src/src/Example.* — sample Aspire applications.
  • src/tests/* — unit and integration tests.

About

Source-generator-powered resource kits for .NET Aspire: turn AppHost resource composition into strongly typed, testable classes with generated host wiring, typed options, and enablement toggles for local, test, and publish modes.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages