Skip to content

Repository files navigation

Purview.Aspire.ResourceKit

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.

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.
  • Predictable lifecycle (Build then Configure) for inter-resource dependencies.
  • 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

Built-in AI agent skills (auto-installed via NuGet)

This package can ship one or more bundled Agent Skills. When a consuming project builds, any skills/**/SKILL.md files in the package are copied to:

  • .agents/skills/**

Example:

  • skills/aspire-apphost-to-resourcekit/SKILL.md.agents/skills/aspire-apphost-to-resourcekit/SKILL.md

It also writes a local .gitignore into each generated skill folder to keep updates out of source control noise.

To disable this behavior, set the shared opt-out property in your project (or Directory.Build.props):

<EnableEmbeddedAgentSkills>false</EnableEmbeddedAgentSkills>

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.

What gets generated

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.

Learn more

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

Composable, test-friendly resource kits for .NET Aspire, with source-generated host integration and reusable resource configuration for local development, testing, and publishing.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages