How to configure Dapr Actors to support specific State?

135 views Asked by At

I am exploring the use of Dapr in my Azure Container App.

Context

I have configured a couple of actors and I am looking how I could configure different Azure Storage Accounts to save the States.

First, I have defined 2 Dapr components in the Azure App Container Environment:

Azure Container App Environment

Then I can confirm the components are available to my Azure Container App:

Azure Container App

Now, following the documentation, I need to set the metadata actorStateStore to true on the component to allow it to be used as state storage for the actors.

Problem

When I access the StateManager in my Actor, I do not see how I can tell Dapr which State Component to use (since I have defined 2) (something possible with Orleans Framework).

For instance:

internal interface IUserCodeActor : IActor
{
    Task CreateAsync
    (
        UserCodeContract userCodeContract
    );
}

internal sealed class UserCodeActor : Actor, IUserCodeActor
{
    private const string DefaultStateName = "user_code_state";
    
    public UserCodeActor(ActorHost actorHost) : base(actorHost)
    {
    }

    public async Task CreateAsync
    (
        UserCodeContract userCodeContract
    )
    {
        //  --> Which Storage Is Used? Can I select it?
        await StateManager.SetStateAsync
        (
            DefaultStateName,
            new UserCodeState
            {
                UserCode = userCodeContract.UserCode.Value,
                ClientId = userCodeContract.ClientId.Value,
                DeviceCode = userCodeContract.DeviceCode.Value
            }
        );

        await StateManager.SaveStateAsync();
    }
}

Question

How do I configure which State Component to use for a given Actor?

0

There are 0 answers