Purview.Aspire.ResourceKit
1.0.0-prerelease.22
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
<PackageReference Include="Purview.Aspire.ResourceKit" Version="1.0.0-prerelease.22" />
<PackageVersion Include="Purview.Aspire.ResourceKit" Version="1.0.0-prerelease.22" />
<PackageReference Include="Purview.Aspire.ResourceKit" />
paket add Purview.Aspire.ResourceKit --version 1.0.0-prerelease.22
#r "nuget: Purview.Aspire.ResourceKit, 1.0.0-prerelease.22"
#:package Purview.Aspire.ResourceKit@1.0.0-prerelease.22
#addin nuget:?package=Purview.Aspire.ResourceKit&version=1.0.0-prerelease.22&prerelease
#tool nuget:?package=Purview.Aspire.ResourceKit&version=1.0.0-prerelease.22&prerelease
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:
Generic attribute (recommended)
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 theResourceBase<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:
- Resource kit instantiation from options.
Buildfor each enabled resource.Configurefor each enabled resource.
This happens before DistributedApplication.Build() completes.
Build/BuildResource vs Configure/ConfigureResource
Buildcalls yourBuildResource(IDistributedApplicationBuilder)override to construct the resource.Configurecalls yourConfigureResource()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
IsEnabledis the current enablement flag (usually sourced from generated options).- During
Build, ResourceKit evaluatesIsResourceEnabled(builder)and assigns that result toIsEnabled. - If disabled, both
BuildResource(...)andConfigureResource()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.
IsEnabledcan 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.Optionsfor host-level values.Optionsfor 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 | Versions 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. |
-
net10.0
- Aspire.Hosting (>= 13.4.6)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Telemetry.Abstractions (>= 10.8.0)
-
net8.0
- Aspire.Hosting (>= 13.4.6)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Telemetry.Abstractions (>= 10.8.0)
-
net9.0
- Aspire.Hosting (>= 13.4.6)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Telemetry.Abstractions (>= 10.8.0)
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 |