Skip to content

Facility to provide interface while registering actors #1350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: release-1.16
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ public void ConfigureServices(IServiceCollection services)
// Register actor runtime with DI
services.AddActors(options =>
{
// Register actor types and configure actor settings
// Register actor types and configure actor settings.
options.Actors.RegisterActor<MyActor>();

// Register MyActor to a specific interface.
options.Actors.RegisterActor<IMyActor, MyActor>();

// Configure default settings
options.ActorIdleTimeout = TimeSpan.FromMinutes(10);
Expand All @@ -150,6 +153,12 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton<BankService>();
}
```
> [!IMPORTANT]
> When registering actors, note the return type requirements for the methods inside the interfaces:
> * Pattern 1: `options.Actors.RegisterActor<MyActor>()`
> * In this case, all interfaces implemented by `MyActor` must have methods that return only `Task` or `Task<T>`. This applies to every method in all interfaces `MyActor` implements.
> * Pattern 2: `options.Actors.RegisterActor<IMyActor, MyActor>()`
> * Here, only the `IMyActor` interface is required to have methods that return `Task` or `Task<T>`. Other interfaces `MyActor` are not subject to this restriction.
Comment on lines +156 to +161
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we force the use of IActor interface we can add a Diagnostics to block the compilation when the derived class contains methods that doesn't return Task<T>. Similar to what is done in the actors' source generator for the CancellationToken (example)

I usually don't like to find out particularities from documentation, if possible I prefer my editor to guide me.

What do you think about it?


### Configuring JSON options

Expand Down Expand Up @@ -241,4 +250,4 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

## Next steps

Try the [Running and using virtual actors example]({{< ref dotnet-actors-howto.md >}}).
Try the [Running and using virtual actors example]({{< ref dotnet-actors-howto.md >}}).