# Akka Hosting Actor Patterns

Patterns for building entity actors with Akka.Hosting - GenericChildPerEntityParent...

- Repository: https://github.com/Aaronontheweb/dotnet-skills (1244 stars)
- Category: Testing
- License: MIT
- Last updated: 2026-10-28
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add Aaronontheweb/dotnet-skills --skill akka-hosting-actor-patterns -g -a claude-code -y`
Codex: `npx skills add Aaronontheweb/dotnet-skills --skill akka-hosting-actor-patterns -g -a codex -y`
Cursor: `npx skills add Aaronontheweb/dotnet-skills --skill akka-hosting-actor-patterns -g -a cursor -y`
Gemini CLI: `npx skills add Aaronontheweb/dotnet-skills --skill akka-hosting-actor-patterns -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add Aaronontheweb/dotnet-skills`

## Description

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.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Akka.Hosting Actor Patterns

## When to Use This Skill

Use this skill when:
- Building entity actors that represent domain objects (users, orders, invoices, etc.)
- Need actors that work in both unit tests (no clustering) and production (cluster sharding)
- Setting up scheduled tasks with akka-reminders
- Registering actors with Akka.Hosting extension methods
- Creating reusable actor configuration patterns

## Core Principles

1. **Execution Mode Abstraction** - Same actor code runs locally (tests) or clustered (production)
2. **GenericChildPerEntityParent for Local** - Mimics sharding semantics without cluster overhead
3. **Message Extractors for Routing** - Reuse Akka.Cluster.Sharding's IMessageExtractor interface
4. **Akka.Hosting Extension Methods** - Fluent configuration that composes well
5. **ITimeProvider for Testability** - Use ActorSystem.Scheduler instead of DateTime.Now

## Execution Modes

Define an enum to control actor behavior:

```csharp
/// <summary>
/// Determines how Akka.NET should be configured
/// </summary>
public enum AkkaExecutionMode
{
    /// <summary>
    /// Pure local actor system - no remoting, no clustering.
    /// Use GenericChildPerEntityParent instead of ShardRegion.
    /// Ideal for unit tests and simple scenarios.
    /// </summary>
    LocalTest,

    /// <summary>
    /// Full clustering with ShardRegion.
    /// Use for integration testing and production.
    /// </summary>
    Clustered
}
```

## GenericChildPerEntityParent

A lightweight parent actor that routes messages to child entities, mimicking cluster sharding semantics without requiring a cluster:

```csharp
using Akka.Actor;
using Akka.Cluster.Sharding;

The rest: https://github.com/Aaronontheweb/dotnet-skills/blob/HEAD/skills/akka-hosting-actor-patterns/SKILL.md
