You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The interface defines the actor contract that is shared between the actor implementation and the clients calling the actor. Because a client may depend on it, it typically makes sense to define it in an assembly that is separate from the actor implementation.
21
+
22
+
```python
23
+
from dapr.actor import ActorInterface, actormethod
24
+
25
+
classDemoActorInterface(ActorInterface):
26
+
@actormethod(name="GetMyData")
27
+
asyncdefget_my_data(self) -> object:
28
+
...
29
+
```
30
+
31
+
## Actor services
32
+
33
+
An actor service hosts the virtual actor. It is implemented a class that derives from the base type `Actor` and implements the interfaces defined in the actor interface.
34
+
35
+
Actors can be created using one of the Dapr actor extensions:
36
+
-[FastAPI actor extension]({{< ref python-fastapi.md >}})
37
+
-[Flask actor extension]({{< ref python-flask.md >}})
38
+
39
+
## Actor client
40
+
41
+
An actor client contains the implementation of the actor client which calls the actor methods defined in the actor interface.
42
+
43
+
```python
44
+
import asyncio
45
+
46
+
from dapr.actor import ActorProxy, ActorId
47
+
from demo_actor_interface import DemoActorInterface
# Test the result directly or test for side effects (like changing state) by querying _state_manager._mock_state
41
98
```
42
99
43
-
## Usage and Limitations
100
+
###Usage and Limitations
44
101
45
102
**The \_on\_activate method will not be called automatically the way it is when Dapr initializes a new Actor instance. You should call it manually as needed as part of your tests.**
46
103
@@ -57,7 +114,7 @@ The actor _runtime_ctx variable is set to None. Obviously all the normal actor m
57
114
58
115
The actor _state_manager is overwritten with an instance of MockStateManager. This has all the same methods and functionality of the base ActorStateManager, except for using the various _mock variables for storing data instead of the _runtime_ctx. If your code implements its own custom state manager it will be overwritten and your code will likely break.
59
116
60
-
## Type Hinting
117
+
###Type Hinting
61
118
62
119
Because of Python's lack of a unified method for type hinting type intersections (see: [python/typing #213](https://github.com/python/typing/issues/213)), type hinting is unfortunately mostly broken with Mock Actors. The return type is type hinted as "instance of Actor subclass T" when it should really be type hinted as "instance of MockActor subclass T" or "instance of type intersection [Actor subclass T, MockActor]" (where, it is worth noting, MockActor is itself a subclass of Actor).
0 commit comments