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
title: Akka.Analyzers Rule AK1008 - "Creating actors using `ActorSystem.ActorOf()` inside an actor"
4
+
---
5
+
6
+
# AK1008 - Warning
7
+
8
+
Creating actors using `Context.System.ActorOf()` inside an actor is discouraged because the resulting actor would not be the child of this actor but the "/user" guardian actor itself. Please use `Context.ActorOf()` if your intention is to create a child actor of this actor.
9
+
10
+
## Cause
11
+
12
+
Creating an `IActorRef` Using `Context.System.ActorOf()` or `Context.System.ActorOf<T>()` inside a class that inherits `ReceiveActor` or `UntypedActor` would create an actor as a child the "/user" guardian actor instead of a child actor under the invoking actor.
13
+
14
+
You can suppress this warning message if you specifically intended to create a new actor under the "/user" guardian actor.
15
+
16
+
Example:
17
+
18
+
```csharp
19
+
usingSystem;
20
+
usingAkka.Actor;
21
+
22
+
publicsealedclassFirstActor : ReceiveActor
23
+
{
24
+
publicFirstActor()
25
+
{
26
+
Context.System.ActorOf<MyActor>("newActor");
27
+
}
28
+
}
29
+
30
+
publicsealedclassMyActor : ReceiveActor
31
+
{
32
+
}
33
+
```
34
+
35
+

36
+
37
+
## Resolution
38
+
39
+
Use `Context.ActorOf()` or `Context.ActorOf<T>()` method instead to create a new child actor:
40
+
41
+
```csharp
42
+
usingSystem;
43
+
usingAkka.Actor;
44
+
45
+
publicsealedclassFirstActor : ReceiveActor
46
+
{
47
+
publicFirstActor()
48
+
{
49
+
Context.ActorOf<MyActor>("newActor");
50
+
}
51
+
}
52
+
53
+
publicsealedclassMyActor : ReceiveActor
54
+
{
55
+
}
56
+
```
57
+
58
+

0 commit comments