Extensions
Extensions are system-wide plugins registered at actor system creation. They provide cross-cutting capabilities (event sourcing, metrics, service registry) accessible from any actor.The Extension interface
ID must be unique, alphanumeric, up to 255 chars. Add domain-specific methods to your concrete type.
Wiring
Pass extensions viaWithExtensions(ext1, ext2, ...) when creating the actor system. Actors access via ctx.Extension(id) or ctx.Extensions() on Context, ReceiveContext, or GrainContext. Type-assert to access your methods.
Use cases
- Event sourcing engine
- Metrics recorder
- Service registry client
- Distributed tracing
Dependencies
Dependencies are per-actor resources injected at spawn time. Unlike extensions, they are scoped to a single actor and must be serializable for cluster relocation.The Dependency interface
Wiring
Dependencies can be injected in two ways:-
At spawn time β Pass via
WithDependencies(dep1, dep2, ...)as aSpawnOption. The actor receives them throughctx.Dependencies()orctx.Dependency(id)inPreStart,Receive, andPostStop. -
Via the actor system β Call
system.Inject(dep1, dep2, ...)after the system has started. This registers the dependency types with the actor systemβs registry, enabling the framework to restore dependencies during cluster topology changes or when creating actors on remote hosts. You typically combine this withWithDependencieswhen spawning: inject first to register the types, then pass them at spawn so the actor receives them.
Use cases
- Database client
- External API client
- Configuration provider