Communityコーディング&開発github.com

aspire-configuration

Aspire AppHost を設定して、明示的なアプリケーション構成を環境変数を介して出力するように構成します。アプリケーションコードを Aspire クライアントやサービスディスカバリから解放します。

aspire-configuration とは?

このスキルは、Aspire ベースのリポジトリにおいて、AppHost からアプリケーションコードへの構成の受け渡しを明示的に行うためのパターンを提供します。主な目的は、アプリケーションプロジェクトが Aspire クライアントパッケージやサービスディスカバリに依存しないようにし、構成を環境変数や設定ファイルベースの透過的なものにすることです。これにより、開発環境と運用環境の構成にパリティが生まれ、Aspire に依存しない移植性の高いアプリケーションを実現できます。具体的には、AppHost 内で `WithEnvironment` を利用してリソースの出力を明示的な構成キーにマッピングし、アプリケーション側では `IOptions<T>` や `Configuration` を通じてのみ値を読み取るアーキテクチャを推奨します。このスキルは、.NET Aspire スタックを使用するすべてのプロジェクトに適用可能で、特に機能トグルやテスト用の設定オーバーライドを実装する際に有効です。

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

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Aspire Configuration

このスキルを使用するタイミング

以下の場合にこのスキルを使用します:

  • Aspire ベースのリポジトリで AppHost リソースをアプリケーション構成に配線する場合
  • 本番環境の構成を透過的かつ Aspire の外部に移植可能にしたい場合
  • アプリケーションコード内で Aspire クライアント/サービスディスカバリパッケージを避けたい場合
  • アプリケーションのコードパスを変更せずに開発/テスト用の機能トグルを設計する場合

基本原則

  1. AppHost が Aspire インフラストラクチャパッケージを管理する

    • Aspire ホスティングパッケージは AppHost のみに属します。
    • アプリケーションプロジェクトは Aspire クライアントやサービスディスカバリパッケージを参照すべきではありません。
  2. 明示的な構成のみを使用する

    • AppHost はリソースの出力を明示的な構成キー (環境変数) に変換する必要があります。
    • アプリケーションコードは IOptions<T> または Configuration にのみバインドします。
  3. 本番環境との同等性と透過性を確保する

    • AppHost によって注入されるすべての値は、Aspire なしで本番環境の環境変数または設定ファイルとして表現可能である必要があります。
    • 不透明なサービスディスカバリや暗黙的な構成は避けてください。

構成フロー

AppHost リソース -> WithEnvironment(...) -> アプリ構成キー -> アプリの IOptions<T>

AppHost は Aspire リソースを明示的なアプリ設定に変換する責任を持ちます。 アプリケーションは Aspire クライアントやサービスディスカバリを直接使用することはありません。


AppHost のパターン (明示的なマッピング)

例: データベース + Blob ストレージ

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

重要なポイント

  • WithReference(db, "Postgres") は ConnectionStrings__Postgres を明示的に設定します。
  • すべての外部依存関係は明示的な構成キーを介して表現されます。
  • API プロジェクトは Configuration 値のみを読み取ります。

アプリケーションコードのパターン (Aspire クライアントなし)

アプリケーションコードはオプションにバインドし、SDK を直接初期化します。Aspire クライアントパッケージやサービスディスカバリに依存してはいけません。

// 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); // 明示的なオプションのみを使用
});

Aspire クライアントパッケージ (または AddServiceDiscovery) をアプリに追加しないでください。 これらはオーケストレーションの関心事であり、AppHost に留めるべきです。


機能トグルとテストオーバーライド

トグルは設定に保持し、AppHost とテストフィクスチャを介して駆動します。これにより、開発/テスト環境と本番環境の設定にパリティが維持されます。

// AppHost: テストでは設定オーバーライドを使用して永続化を無効にする
var config = builder.Configuration.GetSection("App")
    .Get<AppHostConfiguration>() ?? new AppHostConfiguration();

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

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

構成オーバーライドを DistributedApplicationTestingBuilder に渡すパターンについては、skills/aspire/integration-testing/SKILL.md を参照してください。


すべきこと / してはいけないこと チェックリスト

すべきこと

  • すべての Aspire リソースの出力を明示的な構成キーにマッピングする
  • すべてのインフラストラクチャ設定に検証付きの IOptions<T> を使用する
  • AppHost を Aspire ホスティングパッケージを参照する唯一の場所にする
  • AppHost が注入するすべての値が本番環境の環境変数で設定可能であることを確認する

してはいけないこと

  • アプリケーションプロジェクトで Aspire クライアントやサービスディスカバリパッケージを参照する
  • 本番環境でミラーリングできない不透明なサービスディスカバリに依存する
  • 構成を Aspire 限定の抽象化の背後に隠す

関連スキル

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

リソース

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.

関連スキル