Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ Each concept has its own page:
- [Serialization]({{< ref dotnet-actorsnext-serialization.md >}}): the pluggable serializer, and the per-actor cache.
- [State migration]({{< ref dotnet-actorsnext-statemigration.md >}}): The state envelope and versioning state with upcasters.
- [State machine actors]({{< ref dotnet-actorsnext-statemachine.md >}}): the `StateMachineActor` model, when to choose it over a workflow, and how to test it.
- [Subscription streams]({{< ref dotnet-actorsnext-streams.md >}}): driving actors from pub/sub topics with `[Subscribe]`.
- [Subscription streams]({{< ref dotnet-actorsnext-streams.md >}}): driving actors from pub/sub topics with `[Subscribe]` metadata and explicit stream registration.
- [Dynamic invocation]({{< ref dotnet-actorsnext-dynamic.md >}}): calling actors by type, id, and method with no compile-time contract, for gateways, tooling, and cross-language callers.
- [Testing]({{< ref dotnet-actorsnext-testing.md >}}): the in-memory test runtime, xUnit usage, and optional Coyote integration for deep concurrency testing.
- Per-type runtime options are supported through `options.Actors.RegisterActor<TActor>(...)`, including idle timeout, reentrancy, draining, and state-migration overrides.

## Learn by example

If you would rather see the improvements one at a time with runnable code, the [tutorial]({{< ref "tutorial/_index.md" >}}) walks through six worked examples, each paired with its test, with the code in the solution under `/examples/Actor.Next/`. It is the fastest way to understand what changed and why.
If you would rather see the improvements one at a time with runnable code, the [tutorial]({{< ref "tutorial/_index.md" >}}) walks through six worked examples, each paired with its test. The solution also includes a seventh [per-type options example]({{< ref "dotnet-actorsnext-howto.md#per-type-runtime-options" >}}) under `/examples/Actor.Next/`. It is the fastest way to understand what changed and why.

## Next steps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,34 @@ builder.Services.AddDaprActors(options =>
});
```

### Per-type runtime options

Use `options.Actors.RegisterActor<TActor>(...)` when one actor type needs a different runtime profile from the app-wide defaults. Only values set in the per-type delegate override the app-wide options; unset values inherit them.

```csharp
builder.Services.AddDaprActors(options =>
{
options.ActorIdleTimeout = TimeSpan.FromMinutes(30);
options.DrainRebalancedActorsTimeout = TimeSpan.FromSeconds(10);

options.Actors.RegisterActor<CheckoutSessionActor>(typeOptions =>
{
typeOptions.IdleTimeout = TimeSpan.FromMinutes(5);
typeOptions.DisableStateMigration = true;
});

options.Actors.RegisterActor<InventoryActor>(typeOptions =>
{
typeOptions.IdleTimeout = TimeSpan.FromHours(2);
typeOptions.EnableReentrancy = true;
typeOptions.MaxReentrantDepth = 4;
typeOptions.DrainRebalancedActorsTimeout = TimeSpan.FromSeconds(5);
});
});
```

The idle timeout, draining settings, and reentrancy settings are advertised to the Dapr sidecar for the registered actor type. `DisableStateMigration` is applied locally by the SDK when that actor's state is persisted and is not advertised to the sidecar. The complete runnable version is in `examples/Actor.Next/07-PerTypeOptions`.

{{% alert title="There is no lifetime parameter" color="primary" %}}
`AddDaprActors` does not accept a `ServiceLifetime`. An actor's lifetime is its activation, which the runtime owns: it is keyed by id, spans many turns, and ends on deactivation. That is not a DI lifetime, so it is not configurable. The actor instance is constructed per activation in a dedicated DI scope, cached across turns, and disposed together with its scope on deactivation. Your actor's dependencies keep whatever lifetimes you registered them with.
{{% /alert %}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,25 @@ public sealed class CartActor(ActorActivationContext context) : Actor, ICartActo
}
```

The only thing you must supply is the routing key, which determines the actor id that gets the event. Everything else, including opening the subscription, deserializing the event, and forwarding the invocation, is generated, so the surface reads as though the actor subscribes directly. The routing key can be a property of the event, a CloudEvents attribute such as `subject`, or a content path.
The routing key determines the actor id that gets the event. The streaming service opens the subscription, deserializes the event, and forwards the invocation; the application supplies the subscription metadata through the registry. The routing key can be a property of the event, a CloudEvents attribute such as `subject`, or a content path.

Subscriptions are generated from your `[Subscribe]` methods, but the streaming host that opens them is a separate service you opt into. Register it alongside actors at startup:
`[Subscribe]` documents the actor method's subscription target, but the current implementation does not discover that attribute automatically. The application must add the corresponding `ActorStreamSubscription` to the stream registry. The streaming host that opens the subscriptions is a separate service you opt into:

```csharp
builder.Services.AddDaprActors();
builder.Services.AddDaprActorStreams(); // Necessary to register the appropriate types
builder.Services.AddDaprActorStreams();

app.Services.GetRequiredService<ActorStreamSubscriptionRegistry>().Add(
new ActorStreamSubscription(
"orders-pubsub",
"inventory-restocked",
"CartActor",
nameof(ICartActor.OnRestock),
nameof(RestockEvent.CartId)));
```

The registry entry supplies the pub/sub component, topic, actor type, dispatch method, and routing key. The attribute and registry entry should describe the same subscription; the registry is the configuration that the hosted subscriber uses.

## Delivery semantics

The subscription's acknowledgment is gated on the outcome of the forward invocation, so a message is not acknowledged before the actor has processed it.
Expand Down
Loading