$npx -y skills add Aaronontheweb/dotnet-skills --skill akka-aspire-configurationConfigure Akka.NET with .NET Aspire for local development and production deployments. Covers actor system setup, clustering, persistence, Akka.Management integration, and Aspire orchestration patterns.
| 1 | # Configuring Akka.NET with .NET Aspire |
| 2 | |
| 3 | ## When to Use This Skill |
| 4 | |
| 5 | Use this skill when: |
| 6 | - Setting up a new Akka.NET project with .NET Aspire orchestration |
| 7 | - Configuring Akka.Cluster with cluster bootstrapping and discovery |
| 8 | - Integrating Akka.Persistence with SQL Server |
| 9 | - Setting up Akka.Management for cluster management |
| 10 | - Configuring multi-replica actor systems in local development |
| 11 | - Deploying Akka.NET applications to Kubernetes with Aspire |
| 12 | |
| 13 | ## Related Skills |
| 14 | |
| 15 | - **`akka-net-management`** - Deep dive into Akka.Management, Cluster Bootstrap, and discovery providers (Kubernetes, Azure, Config) |
| 16 | - **`microsoft-extensions-configuration`** - IValidateOptions patterns for configuration validation |
| 17 | - **`akka-net-best-practices`** - Cluster/local mode abstractions for testable actor systems |
| 18 | - **`aspire-integration-testing`** - Testing Aspire applications with real infrastructure |
| 19 | |
| 20 | ## Core Principles |
| 21 | |
| 22 | 1. **Configuration via Microsoft.Extensions.Configuration** - Use strongly-typed settings classes bound from appsettings.json (see `microsoft-extensions-configuration` skill) |
| 23 | 2. **Akka.Hosting for DI Integration** - Use the Akka.Hosting library for seamless ASP.NET Core integration |
| 24 | 3. **Aspire for Orchestration** - Let Aspire manage service dependencies, networking, and environment configuration |
| 25 | 4. **Health Checks** - Always configure health checks for clustering, persistence, and readiness |
| 26 | 5. **Separate Concerns** - Keep actor definitions, configuration, and Aspire orchestration in separate layers |
| 27 | 6. **Validate Configuration at Startup** - Use `IValidateOptions<T>` and `.ValidateOnStart()` to fail fast on misconfiguration |
| 28 | |
| 29 | ## Project Structure |
| 30 | |
| 31 | ``` |
| 32 | YourSolution/ |
| 33 | ├── src/ |
| 34 | │ ├── YourApp.Actors/ # Actor definitions and business logic |
| 35 | │ │ ├── YourActor.cs |
| 36 | │ │ └── YourApp.Actors.csproj |
| 37 | │ ├── YourApp/ # ASP.NET Core web application |
| 38 | │ │ ├── Config/ |
| 39 | │ │ │ ├── AkkaConfiguration.cs # Akka setup extension methods |
| 40 | │ │ │ └── AkkaSettings.cs # Configuration model |
| 41 | │ │ ├── Program.cs |
| 42 | │ │ ├── appsettings.json |
| 43 | │ │ └── YourApp.csproj |
| 44 | │ └── YourApp.AppHost/ # Aspire orchestration |
| 45 | │ ├── Program.cs |
| 46 | │ ├── AkkaManagementExtensions.cs |
| 47 | │ └── YourApp.AppHost.csproj |
| 48 | ``` |
| 49 | |
| 50 | ## Required NuGet Packages |
| 51 | |
| 52 | ### For Actor Project (YourApp.Actors.csproj) |
| 53 | ```xml |
| 54 | <ItemGroup> |
| 55 | <PackageReference Include="Akka.Cluster.Hosting" /> |
| 56 | <PackageReference Include="Akka.Streams" /> |
| 57 | </ItemGroup> |
| 58 | ``` |
| 59 | |
| 60 | ### For Web Application (YourApp.csproj) |
| 61 | ```xml |
| 62 | <ItemGroup> |
| 63 | <PackageReference Include="Akka.Hosting" /> |
| 64 | <PackageReference Include="Akka.Cluster.Hosting" /> |
| 65 | <PackageReference Include="Akka.Persistence.Sql.Hosting" /> |
| 66 | <PackageReference Include="Akka.Management" /> |
| 67 | <PackageReference Include="Akka.Management.Cluster.Bootstrap" /> |
| 68 | <PackageReference Include="Akka.Discovery.KubernetesApi" /> |
| 69 | <PackageReference Include="Akka.Discovery.Azure" /> |
| 70 | <PackageReference Include="Akka.Discovery.Config.Hosting" /> |
| 71 | <PackageReference Include="Petabridge.Cmd.Host" /> |
| 72 | <PackageReference Include="Petabridge.Cmd.Cluster" /> |
| 73 | </ItemGroup> |
| 74 | ``` |
| 75 | |
| 76 | ### For AppHost (YourApp.AppHost.csproj) |
| 77 | ```xml |
| 78 | <Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireVersion)" /> |
| 79 | |
| 80 | <ItemGroup> |
| 81 | <PackageReference Include="Aspire.Hosting.AppHost" /> |
| 82 | <PackageReference Include="Aspire.Hosting.Azure.Storage" /> |
| 83 | <PackageReference Include="Aspire.Hosting.SqlServer" /> |
| 84 | </ItemGroup> |
| 85 | ``` |
| 86 | |
| 87 | ## Configuration Model (AkkaSettings.cs) |
| 88 | |
| 89 | Create a strongly-typed configuration class: |
| 90 | |
| 91 | ```csharp |
| 92 | using System.Net; |
| 93 | using System.Security.Cryptography.X509Certificates; |
| 94 | using Akka.Cluster.Hosting; |
| 95 | using Akka.Remote.Hosting; |
| 96 | using Petabridge.Cmd.Host; |
| 97 | |
| 98 | namespace YourApp.Config; |
| 99 | |
| 100 | public class AkkaSettings |
| 101 | { |
| 102 | public string ActorSystemName { get; set; } = "YourSystem"; |
| 103 | |
| 104 | public bool LogConfigOnStart { get; set; } = false; |
| 105 | |
| 106 | public RemoteOptions RemoteOptions { get; set; } = new() |
| 107 | { |
| 108 | PublicHostName = Dns.GetHostName(), |
| 109 | HostName = "0.0.0.0", |
| 110 | Port = 8081 |
| 111 | }; |
| 112 | |
| 113 | public ClusterOptions ClusterOptions { get; set; } = new() |
| 114 | { |
| 115 | SeedNodes = [$"akka.tcp://YourSystem@{Dns.GetHostName()}:8081"], |
| 116 | Roles = ["your-role"] |
| 117 | }; |
| 118 | |
| 119 | public ShardOptions ShardOptions { get; set; } = new(); |
| 120 | |
| 121 | public AkkaManagementOptions? AkkaManagementOptions { get; set; } |
| 122 | |
| 123 | public PetabridgeCmdOptions PbmOptions { get; set; } = new() |
| 124 | { |
| 125 | Host = "0.0.0.0", |
| 126 | Port = 9110 |
| 127 | }; |
| 128 | |
| 129 | public TlsSettings? TlsSettings { get; set; } |
| 130 | } |
| 131 | |
| 132 | public class TlsSettings |
| 133 | { |
| 134 | public bool Enabled { get; set; } = false; |
| 135 | public string? CertificatePath { get; set; } |
| 136 | public string? CertificatePassword { get; set; } |
| 137 | publ |