Community程式設計與開發github.com

akka-net-aspire-configuration

使用 .NET Aspire 配置 Akka.NET,適用於本地開發和生產部署。涵蓋 Actor 系統設定、叢集、持久化、Akka.Management 整合以及 Aspire 協調模式。

akka-net-aspire-configuration 是什麼?

此技能提供一個全面的指南,用於將 Akka.NET 與 .NET Aspire 整合,以構建模組化、雲端原生的 Actor 系統。它涵蓋從使用 Microsoft.Extensions.Configuration 和 Akka.Hosting 進行強型別 Actor 系統設定,到配置 Akka.Cluster 進行叢引導和服務發現的整個過程。關鍵功能包括與 SQL Server 的 Akka.Persistence 整合、用於叢集管理的 Akka.Management,以及透過 Aspire 進行多副本 Actor 系統的協調。此技能支援多種發現方法,包括 Config、Kubernetes 和 Azure 表儲存,特別強調健康檢查、啟動時驗證以及大型應用程式的關注點分離。適合在類似於 Claude Code、Cursor 或 Codex 的開發環境中使用。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Aaronontheweb/dotnet-skills/tree/main/skills/akka-aspire-configuration

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

使用 .NET Aspire 配置 Akka.NET

何時使用此技能

在以下情況使用此技能:

  • 使用 .NET Aspire 協調建立新的 Akka.NET 專案
  • 配置具有叢引導和服務發現的 Akka.Cluster
  • 整合 SQL Server 的 Akka.Persistence
  • 設定 Akka.Management 以進行叢集管理
  • 在本地開發中配置多副本 Actor 系統
  • 使用 Aspire 將 Akka.NET 應用程式部署到 Kubernetes

相關技能

  • akka-net-management - 深入探討 Akka.Management、叢集引導以及發現提供者(Kubernetes、Azure、Config)
  • microsoft-extensions-configuration - 用於配置驗證的 IValidateOptions 模式
  • akka-net-best-practices - 用於可測試 Actor 系統的叢集/本地模式抽象
  • aspire-integration-testing - 使用真實基礎設施測試 Aspire 應用程式

核心原則

  1. 透過 Microsoft.Extensions.Configuration 進行配置 - 使用從 appsettings.json 繫結的強型別設定類別(請參閱 microsoft-extensions-configuration 技能)
  2. 使用 Akka.Hosting 進行 DI 整合 - 使用 Akka.Hosting 程式庫實現與 ASP.NET Core 的無縫整合
  3. 使用 Aspire 進行協調 - 讓 Aspire 管理服務依賴項、網路和環境配置
  4. 健康檢查 - 始終為叢集、持久化以及就緒狀態配置健康檢查
  5. 關注點分離 - 將 Actor 定義、配置和 Aspire 協調保持在獨立的層次中
  6. 在啟動時驗證配置 - 使用 IValidateOptions<T> 和 .ValidateOnStart() 來在配置錯誤時快速失敗

專案結構

YourSolution/
├── src/
│   ├── YourApp.Actors/              # Actor 定義與業務邏輯
│   │   ├── YourActor.cs
│   │   └── YourApp.Actors.csproj
│   ├── YourApp/                     # ASP.NET Core Web 應用程式
│   │   ├── Config/
│   │   │   ├── AkkaConfiguration.cs  # Akka 設定擴充方法
│   │   │   └── AkkaSettings.cs       # 配置模型
│   │   ├── Program.cs
│   │   ├── appsettings.json
│   │   └── YourApp.csproj
│   └── YourApp.AppHost/             # Aspire 協調
│       ├── Program.cs
│       ├── AkkaManagementExtensions.cs
│       └── YourApp.AppHost.csproj

必要的 NuGet 套件

用於 Actor 專案 (YourApp.Actors.csproj)

<ItemGroup>
  <PackageReference Include="Akka.Cluster.Hosting" />
  <PackageReference Include="Akka.Streams" />
</ItemGroup>

用於 Web 應用程式 (YourApp.csproj)

<ItemGroup>
  <PackageReference Include="Akka.Hosting" />
  <PackageReference Include="Akka.Cluster.Hosting" />
  <PackageReference Include="Akka.Persistence.Sql.Hosting" />
  <PackageReference Include="Akka.Management" />
  <PackageReference Include="Akka.Management.Cluster.Bootstrap" />
  <PackageReference Include="Akka.Discovery.KubernetesApi" />
  <PackageReference Include="Akka.Discovery.Azure" />
  <PackageReference Include="Akka.Discovery.Config.Hosting" />
  <PackageReference Include="Petabridge.Cmd.Host" />
  <PackageReference Include="Petabridge.Cmd.Cluster" />
</ItemGroup>

用於 AppHost (YourApp.AppHost.csproj)

<Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireVersion)" />

<ItemGroup>
  <PackageReference Include="Aspire.Hosting.AppHost" />
  <PackageReference Include="Aspire.Hosting.Azure.Storage" />
  <PackageReference Include="Aspire.Hosting.SqlServer" />
</ItemGroup>

配置模型 (AkkaSettings.cs)

建立一個強型別的配置類別:

using System.Net;
using System.Security.Cryptography.X509Certificates;
using Akka.Cluster.Hosting;
using Akka.Remote.Hosting;
using Petabridge.Cmd.Host;

namespace YourApp.Config;

public class AkkaSettings
{
    public string ActorSystemName { get; set; } = "YourSystem";

    public bool LogConfigOnStart { get; set; } = false;

    public RemoteOptions RemoteOptions { get; set; } = new()
    {
        PublicHostName = Dns.GetHostName(),
        HostName = "0.0.0.0",
        Port = 8081
    };

    public ClusterOptions ClusterOptions { get; set; } = new()
    {
        SeedNodes = [$

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-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-configuration

Configure Aspire AppHost to emit explicit app config via environment variables; keep app code free of Aspire clients and service discovery.

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.

相關技能