Dapr actor .NET usage guide

    Inside of an class or otherwise inside of an ASP.NET Core project you should use the IActorProxyFactory interface to create actor clients.

    The AddActors(...) method will register actor services with ASP.NET Core dependency injection.

    • Inside an actor instance, the IActorProxyFactory instance is available as a property (this.ProxyFactory).

    The following is an example of creating a proxy inside an actor:

    In order to communicate with an actor, you will need to know its type and id, and for a strongly-typed client one of its interfaces. All of the APIs on IActorProxyFactory will require an actor type and actor id.

    • The actor type uniquely identifies the actor implementation across the whole application.

    If you do not have an actor id and want to communicate with a new instance, you can use ActorId.CreateRandom() to create a randomized id. Since the random id is a cryptographically strong identifier, the runtime will create a new actor instance when you interact with it.

    You can use the type ActorReference to exchange an actor type and actor id with other actors as part of messages.

    The actor client supports two different styles of invocation: strongly-typed clients that use .NET interfaces and weakly-typed clients that use the ActorProxy class.

    Use the CreateActorProxy<> method to create a strongly-typed client like the following example. requires an actor interface type, and will return an instance of that interface.

    Using a weakly-typed client

    Use the Create method to create a weakly-typed client like the following example. Create returns an instance of ActorProxy.

    Since ActorProxy is a weakly-typed proxy you need to pass in the actor method name as a string.

    You can also use ActorProxy to invoke methods with a request message and response message. Request and response messages will be serialized using the System.Text.Json serializer.