CommunityCodierung & Entwicklunggithub.com

Aspire-Konfiguration

Konfiguriere den Aspire AppHost so, dass er explizite App-Konfiguration über Umgebungsvariablen bereitstellt; halte den Anwendungscode frei von Aspire-Clients und Service Discovery.

Was ist Aspire-Konfiguration?

Dieses Skill beschreibt, wie Aspire AppHost-Ressourcen in explizite Konfigurationsschlüssel (Umgebungsvariablen) übersetzt werden, sodass die Anwendung selbst keine Aspire-Client- oder Service-Discovery-Pakete benötigt. Es stellt sicher, dass die Produktionskonfiguration transparent und portabel außerhalb von Aspire ist, indem AppHost die einzige Stelle bleibt, die Aspire-Hosting-Pakete referenziert. Die Anwendung bindet ausschließlich an `IOptions<T>` oder `Configuration` und initialisiert SDKs direkt, ohne auf Aspire-Abstraktionen angewiesen zu sein. Das Skill wird in Cursor, Codex und ähnlichen KI-Agenten-Plattformen verwendet und bietet konkrete Codebeispiele für AppHost-Mapping, App-Code-Muster sowie Feature-Toggles in Entwicklungs-/Testumgebungen.

Funktioniert mit✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Aaronontheweb/dotnet-skills/tree/main/skills/aspire-configuration

Installed? Explore more Codierung & Entwicklung skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

In Ihrer bevorzugten KI fragen

Öffnet einen neuen Chat, in dem dieser Agent-Skill bereits geladen ist.

Dokumentation

Was macht Aspire-Konfiguration?

Wann dieses Skill verwendet werden soll

Verwende dieses Skill, wenn:

  • AppHost-Ressourcen mit der Anwendungskonfiguration in Aspire-basierten Repos verbunden werden
  • Sichergestellt werden soll, dass die Produktionskonfiguration transparent und außerhalb von Aspire portabel ist
  • Aspire-Client-/Service-Discovery-Pakete im Anwendungscode vermieden werden sollen
  • Feature-Toggles für Entwicklungs-/Testumgebungen entworfen werden, ohne die Anwendungspfade zu ändern

Kernprinzipien

  1. AppHost besitzt Aspire-Infrastrukturpakete

    • Aspire-Hosting-Pakete gehören ausschließlich in den AppHost.
    • App-Projekte sollten keine Aspire-Client-/Service-Discovery-Pakete referenzieren.
  2. Nur explizite Konfiguration

    • Der AppHost muss Ressourcenausgaben in explizite Konfigurationsschlüssel (Umgebungsvariablen) übersetzen.
    • Der Anwendungscode bindet nur an IOptions<T> oder Configuration.
  3. Produktionsparität und Transparenz

    • Jeder vom AppHost injizierte Wert muss in der Produktion als Umgebungsvariable oder Konfigurationsdatei ohne Aspire darstellbar sein.
    • Vermeide undurchsichtige Service Discovery und implizite Konfiguration.

Konfigurationsablauf

AppHost-Ressource -> WithEnvironment(...) -> App-Konfigurationsschlüssel -> IOptions<T> in der App

Der AppHost ist dafür verantwortlich, Aspire-Ressourcen in explizite App-Einstellungen umzuwandeln. Die Anwendung nutzt niemals direkt Aspire-Clients oder Service Discovery.


AppHost-Muster (Explizites Mapping)

Beispiel: Datenbank + Blob-Speicher

// AppHost/Program.cs
var builder = DistributedApplication.CreateBuilder(args);

var postgres = builder.AddPostgres("postgres");
var db = postgres.AddDatabase("appdb");

var minio = builder.AddContainer("minio", "minio/minio")
    .WithArgs("server", "/data")
    .WithHttpEndpoint(targetPort: 9000, name: "http")
    .WithHttpEndpoint(targetPort: 9001, name: "console")
    .WithEnvironment("MINIO_ROOT_USER", "minioadmin")
    .WithEnvironment("MINIO_ROOT_PASSWORD", "minioadmin");

var api = builder.AddProject<Projects.MyApp_Api>("api")
    .WithReference(db, "Postgres")
    .WithEnvironment("BlobStorage__Enabled", "true")
    .WithEnvironment("BlobStorage__ServiceUrl", minio.GetEndpoint("http"))
    .WithEnvironment("BlobStorage__AccessKey", "minioadmin")
    .WithEnvironment("BlobStorage__SecretKey", "minioadmin")
    .WithEnvironment("BlobStorage__Bucket", "attachments")
    .WithEnvironment("BlobStorage__ForcePathStyle", "true");

builder.Build().Run();

Wichtige Punkte

  • WithReference(db, "Postgres") setzt ConnectionStrings__Postgres explizit.
  • Jede externe Abhängigkeit wird über explizite Konfigurationsschlüssel dargestellt.
  • Das API-Projekt liest nur Configuration-Werte.

App-Code-Muster (Keine Aspire-Clients)

Der Anwendungscode bindet an Optionen und initialisiert SDKs direkt. Er hängt niemals von Aspire-Client-Paketen oder Service Discovery ab.

// Api/Program.cs
builder.Services
    .AddOptions<BlobStorageOptions>()
    .BindConfiguration("BlobStorage")
    .ValidateDataAnnotations()
    .ValidateOnStart();

builder.Services.AddSingleton<IBlobStorageService>(sp =>
{
    var options = sp.GetRequiredService<IOptions<BlobStorageOptions>>().Value;
    return new S3BlobStorageService(options); // verwendet nur explizite Optionen
});

Füge keine Aspire-Client-Pakete (oder AddServiceDiscovery) zur App hinzu. Diese gehören zu den Orchestrierungsbelangen und sollten im AppHost bleiben.


Feature-Toggles und Test-Überschreibungen

Halte Toggles in der Konfiguration und steuere sie über AppHost und Test-Fixtures. Dies bewahrt die Parität zwischen Entwicklungs-/Test- und Produktionskonfiguration.

// AppHost: Deaktiviere Persistenz in Tests über Konfigurationsüberschreibungen
var config = builder.Configuration.GetSection("App")
    .Get<AppHostConfiguration>() ?? new AppHostConfiguration();

if (!config.UseVolumes)
{
    postgres.WithDataVolume(false);
}

api.WithEnvironment("BlobStorage__Enabled", config.EnableBlobStorage.ToString());

Siehe skills/aspire/integration-testing/SKILL.md für Muster, um Konfigurationsüberschreibungen an DistributedApplicationTestingBuilder zu übergeben.


Do's und Don'ts-Checkliste

Do's

  • Bilde jede Aspire-Ressourcenausgabe auf explizite Konfigurationsschlüssel ab
  • Verwende IOptions<T> mit Validierung für alle Infrastruktureinstellungen
  • Halte AppHost als einzigen Ort, der Aspire-Hosting-Pakete referenziert
  • Stelle sicher, dass jeder vom AppHost injizierte Wert in Produktionsumgebungsvariablen gesetzt werden kann

Don'ts

  • Referenziere Aspire-Client-/Service-Discovery-Pakete in Anwendungsprojekten
  • Verlasse dich auf undurchsichtige Service Discovery, die nicht in der Produktion gespiegelt werden kann
  • Verstecke Konfiguration hinter Aspire-only-Abstraktionen

Verwandte Skills

  • skills/aspire/service-defaults/SKILL.md
  • skills/aspire/integration-testing/SKILL.md
  • skills/akka/aspire-configuration/SKILL.md

Ressourcen

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

akka-hosting-actor-patterns

Patterns for building entity actors with Akka.Hosting - GenericChildPerEntityParent, message extractors, cluster sharding abstraction, akka-reminders, and ITimeProvider. Supports both local testing and clustered production modes.

akka-net-aspire-configuration

Configure Akka.NET with .NET Aspire for local development and production deployments. Covers actor system setup, clustering, persistence, Akka.Management integration, and Aspire orchestration patterns.

akka-net-best-practices

Critical Akka.NET best practices including EventStream vs DistributedPubSub, supervision strategies, error handling, Props vs DependencyResolver, work distribution patterns, and cluster/local mode abstractions for testability.

akka-net-management

Akka.Management for cluster bootstrapping, service discovery (Kubernetes, Azure, Config), health checks, and dynamic cluster formation without static seed nodes.

akka-net-testing-patterns

Write unit and integration tests for Akka.NET actors using modern Akka.Hosting.TestKit patterns. Covers dependency injection, TestProbes, persistence testing, and actor interaction verification. Includes guidance on when to use traditional TestKit.

api-design

Design stable, compatible public APIs using extend-only design principles. Manage API compatibility, wire compatibility, and versioning for NuGet packages and distributed systems.

aspire-integration-testing

Write integration tests using .NET Aspire

aspire-service-defaults

Create a shared ServiceDefaults project for Aspire applications. Centralizes OpenTelemetry, health checks, resilience, and service discovery configuration across all services.

crap-analysis

Analyze code coverage and CRAP (Change Risk Anti-Patterns) scores to identify high-risk code. Use OpenCover format with ReportGenerator for Risk Hotspots showing cyclomatic complexity and untested code paths.

csharp-concurrency-patterns

Choosing the right concurrency abstraction in .NET - from async/await for I/O to Channels for producer/consumer to Akka.NET for stateful entity management. Avoid locks and manual synchronization unless absolutely necessary.

database-performance

Database access patterns for performance. Separate read/write models, avoid N+1 queries, use AsNoTracking, apply row limits, and never do application-side joins. Works with EF Core and Dapper.

dependency-injection-patterns

Organize DI registrations using IServiceCollection extension methods. Group related services into composable Add* methods for clean Program.cs and reusable configuration in tests.

dotnet-devcert-trust

Diagnose and fix .NET HTTPS dev certificate trust issues on Linux. Covers the full certificate lifecycle from generation to system CA bundle inclusion, with distro-specific guidance for Ubuntu, Fedora, Arch, and WSL2.

dotnet-local-tools

Managing local .NET tools with dotnet-tools.json for consistent tooling across development environments and CI/CD pipelines.

dotnet-project-structure

Modern .NET project structure including .slnx solution format, Directory.Build.props, central package management, SourceLink, version management with RELEASE_NOTES.md, and SDK pinning with global.json.

dotnet-slopwatch

Use Slopwatch to detect LLM reward hacking in .NET code changes. Run after every code modification to catch disabled tests, suppressed warnings, empty catch blocks, and other shortcuts that mask real problems.

efcore-patterns

Entity Framework Core best practices including NoTracking by default, query splitting for navigation collections, migration management, dedicated migration services, and common pitfalls to avoid.

ilspy-decompile

Understand implementation details of .NET code by decompiling assemblies. Use when you want to see how a .NET API works internally, inspect NuGet package source, view framework implementation, or understand compiled .NET binaries.

mailpit-integration

Test email sending locally using Mailpit with .NET Aspire. Captures all outgoing emails without sending them. View rendered HTML, inspect headers, and verify delivery in integration tests.

marketplace-publishing

Workflow for publishing skills and agents to the dotnet-skills Claude Code marketplace. Covers adding new content, updating plugin.json, validation, and release tagging.

Verwandte Skills