-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Docs] Add AK1008 documentation (#7504)
- Loading branch information
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
uid: AK1008 | ||
title: Akka.Analyzers Rule AK1008 - "Creating actors using `ActorSystem.ActorOf()` inside an actor" | ||
--- | ||
|
||
# AK1008 - Warning | ||
|
||
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. | ||
|
||
## Cause | ||
|
||
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. | ||
|
||
You can suppress this warning message if you specifically intended to create a new actor under the "/user" guardian actor. | ||
|
||
Example: | ||
|
||
```csharp | ||
using System; | ||
using Akka.Actor; | ||
|
||
public sealed class FirstActor : ReceiveActor | ||
{ | ||
public FirstActor() | ||
{ | ||
Context.System.ActorOf<MyActor>("newActor"); | ||
} | ||
} | ||
|
||
public sealed class MyActor : ReceiveActor | ||
{ | ||
} | ||
``` | ||
|
||
 | ||
|
||
## Resolution | ||
|
||
Use `Context.ActorOf()` or `Context.ActorOf<T>()` method instead to create a new child actor: | ||
|
||
```csharp | ||
using System; | ||
using Akka.Actor; | ||
|
||
public sealed class FirstActor : ReceiveActor | ||
{ | ||
public FirstActor() | ||
{ | ||
Context.ActorOf<MyActor>("newActor"); | ||
} | ||
} | ||
|
||
public sealed class MyActor : ReceiveActor | ||
{ | ||
} | ||
``` | ||
|
||
 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.