Purview.Aspire.ResourceKit 1.0.0-prerelease.22

This is a prerelease version of Purview.Aspire.ResourceKit.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Purview.Aspire.ResourceKit --version 1.0.0-prerelease.22
                    
NuGet\Install-Package Purview.Aspire.ResourceKit -Version 1.0.0-prerelease.22
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Purview.Aspire.ResourceKit" Version="1.0.0-prerelease.22" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Purview.Aspire.ResourceKit" Version="1.0.0-prerelease.22" />
                    
Directory.Packages.props
<PackageReference Include="Purview.Aspire.ResourceKit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Purview.Aspire.ResourceKit --version 1.0.0-prerelease.22
                    
#r "nuget: Purview.Aspire.ResourceKit, 1.0.0-prerelease.22"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Purview.Aspire.ResourceKit@1.0.0-prerelease.22
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Purview.Aspire.ResourceKit&version=1.0.0-prerelease.22&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Purview.Aspire.ResourceKit&version=1.0.0-prerelease.22&prerelease
                    
Install as a Cake Tool

Purview.Aspire.ResourceKit (NuGet package)

This package contains the runtime abstractions and source-generator contracts for building Aspire AppHost resources using strongly typed classes.

Use this README when integrating the Purview.Aspire.ResourceKit NuGet package into your host project.

Package goals

  • Keep AppHost resource composition explicit and testable.
  • Generate repetitive registration/configuration code from attributes.
  • Provide strongly typed options for host and resource toggles.

Public attributes

HostKitAttribute ([HostKit])

Marks the single host kit class per compilation.

[HostKit]
sealed partial class ShopHostKit;

Optional named arguments:

  • Name — controls generated naming.
  • ExtensionMethodName — overrides generated builder extension name.
  • GenerateOptions — enables/disables generated host options.

ResourceDefinitionAttribute ([ResourceDefinition])

Marks a resource kit class that participates in generation.

[ResourceDefinition<ProjectResource>("api", PropertyName = "API")]
partial class APIResourceKit;

Options:

  • Name — logical Aspire resource name.
  • PropertyName — generated host property name.

ResourceDefinition vs ResourceDefinition<TResource>

ResourceKit supports two declaration styles, with different base-type behavior:

Use [ResourceDefinition<TResource>] when you want the resource type declared directly on the attribute.

[ResourceDefinition<ProjectResource>("api")]
partial class APIResourceKit
{
    protected override IResourceBuilder<ProjectResource> BuildResource(IDistributedApplicationBuilder builder)
        => builder.AddProject<Projects.Example_Service>(Name);
}
  • Do not declare an explicit base type on the class.
  • The generator supplies the host-specific base in generated partial code.
Non-generic attribute

Use [ResourceDefinition] when you prefer (or need) to specify the resource type through an explicit base type.

[ResourceDefinition("api")]
partial class APIResourceKit : ShopHostKitResourceBase<ProjectResource>
{
    protected override IResourceBuilder<ProjectResource> BuildResource(IDistributedApplicationBuilder builder)
        => builder.AddProject<Projects.Example_Service>(Name);
}
  • You must declare an explicit valid base type.
  • Typically this is the generated host-specific base (ResourceBase<TResource>, unlike the ResourceBase<THostKit, TResource> that takes the explicit Host Kit as a construction parameter).

Do not mix both attribute styles on the same class.

Minimal package usage

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

Generated output (high level)

From your attributed partial classes, the generator emits:

  • a host base type for resources ({Host}ResourceBase<TResource>),
  • host members for each resource definition,
  • generated options types (when enabled),
  • a builder extension method for registration and lifecycle execution.

Runtime lifecycle

When the generated extension is invoked, ResourceKit performs:

  1. Resource kit instantiation from options.
  2. Build for each enabled resource.
  3. Configure for each enabled resource.

This happens before DistributedApplication.Build() completes.

Build/BuildResource vs Configure/ConfigureResource

  • Build calls your BuildResource(IDistributedApplicationBuilder) override to construct the resource.
  • Configure calls your ConfigureResource() override to attach resources to each other after construction.

This separation keeps creation and cross-resource wiring explicit and deterministic.

How IsEnabled and IsResourceEnabled(...) interact

  • IsEnabled is the current enablement flag (usually sourced from generated options).
  • During Build, ResourceKit evaluates IsResourceEnabled(builder) and assigns that result to IsEnabled.
  • If disabled, both BuildResource(...) and ConfigureResource() are skipped for that resource.

Override IsResourceEnabled(builder) when enablement should react to runtime state rather than only static options.

Options and configuration

When options are generated:

  • Host options root section is the generated host options type name (or configured section).
  • Resource options are nested by generated resource property name.
  • IsEnabled can be used to skip a resource at runtime.

See detailed patterns in /docs/configuration.md.

Extending generated typed options

Generated host and resource options are sealed partial nested classes. You can safely extend them by adding matching partial declarations in your own code.

Host options extension example:

[HostKit]
partial class ExampleHostKit
{
    public sealed partial class ExampleHostKitOptions
    {
        public bool EnablePreviewResources { get; set; }
    }
}

Resource options extension example:

[ResourceDefinition<ProjectResource>("api")]
sealed partial class ExampleAPIKit
{
    partial class ExampleAPIKitOptions
    {
        public string PublishEnvironmentVariableName { get; set; } = "PUBLISH_MARKER";
    }
}

Use these values through generated properties:

  • HostKit.Options for host-level values.
  • Options for each resource kit instance.

OptionsHelper (tests and CLI args)

OptionsHelper converts typed assignment expressions into command-line configuration args:

var args = OptionsHelper.ForSet<ExampleHostKit.ExampleHostKitOptions>(
    c => c.Redis.IsEnabled = false,
    c => c.Redis.Name = "dev-redis"
).Build();

For a single value, use ForOne with a member selector and access the first element:

var arg = OptionsHelper.ForOne<ExampleHostKit.ExampleHostKitOptions>(f => f.Redis.Name).Build()[0];

Produces values like:

  • --ExampleHostKit:Redis:IsEnabled=false
  • --ExampleHostKit:Redis:Name=dev-redis

Switch to environment variables with AsEnvironmentVariables():

var envVars = OptionsHelper.ForSet<ExampleHostKit.ExampleHostKitOptions>(
    c => c.Redis.IsEnabled = false
).AsEnvironmentVariables().Build();

Useful for integration-test fixtures and scenario toggles.

Diagnostics

ID Severity Description
SG0001 Error Class must be partial
SG0002 Info No resources defined for the host kit
SG0003 Warning No host kit defined (but resources exist)
SG0004 Error Multiple [HostKit] classes defined
SG0005 Error Duplicate resource property name
SG0006 Error Resource must derive from expected generated base
SG0007 Error Resource name could not be derived and no Name was specified
SG0008 Error Explicit PropertyName is not a valid C# identifier
SG0009 Error Missing IServiceCollection type dependency
SG0010 Error Missing configuration binder dependency
SG0011 Error Missing options configuration extensions dependency
SG0012 Error Non-empty constructors are not supported on attributed classes
SG0013 Error Mixed ResourceDefinition and ResourceDefinition<TResource> on the same class is not supported
SG0014 Error Non-generic ResourceDefinition requires an explicit compatible base type
SG0015 Error Generic ResourceDefinition<TResource> must not declare an explicit base type
SG0016 Error No Aspire resource type could be inferred/found

For troubleshooting guidance, see /docs/diagnostics.md.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-prerelease.24 49 9/8/2026
1.0.0-prerelease.23 63 9/3/2026
1.0.0-prerelease.22 60 9/3/2026
1.0.0-prerelease.21 65 9/2/2026
1.0.0-prerelease.20 62 8/27/2026
1.0.0-prerelease.19 108 8/16/2026
1.0.0-prerelease.18 69 8/14/2026
1.0.0-prerelease.17 67 8/13/2026
1.0.0-prerelease.16 64 8/12/2026
1.0.0-prerelease.15 70 8/10/2026
1.0.0-prerelease.14 64 8/5/2026
1.0.0-prerelease.13 61 8/5/2026
1.0.0-prerelease.12 70 8/4/2026
1.0.0-prerelease.11 75 8/2/2026
1.0.0-prerelease.10 70 8/2/2026
1.0.0-prerelease.9 78 7/31/2026
1.0.0-prerelease.8 71 7/29/2026
1.0.0-prerelease.7 68 7/28/2026
1.0.0-prerelease.6 73 7/27/2026
1.0.0-prerelease.5 71 7/26/2026
Loading failed