-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add MAUI support #293
Add MAUI support #293
Conversation
private readonly ILogger<AkkaHostedService> _logger; | ||
|
||
public AkkaHostedService(AkkaConfigurationBuilder configurationBuilder, IServiceProvider serviceProvider, | ||
ILogger<AkkaHostedService> logger, IHostApplicationLifetime applicationLifetime) | ||
ILogger<AkkaHostedService> logger, IHostApplicationLifetime? applicationLifetime) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MAUI does not support IHostApplicationLife
, we need to pass in null
and disable termination hook.
services.AddHostedService<AkkaHostedService>(); | ||
if (Util.IsRunningInMaui) | ||
{ | ||
services.AddSingleton<AkkaHostedService>(provider => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MAUI does not support hosting, hosted services had to be registered as a singleton service.
src/Akka.Hosting/MauiSupport.cs
Outdated
{ | ||
public static class AkkaMauiSupport | ||
{ | ||
public static async Task StartAkka(IServiceProvider provider, CancellationToken token = default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Akka hosted service have to be started manually by users, AkkaHostedService
is internal, we have to use these wrapper methods to let user call the service StartAsync()
method
{ | ||
get | ||
{ | ||
_runningInMaui ??= AppDomain.CurrentDomain.GetAssemblies().Any(asm => asm.GetName().Name.StartsWith("Microsoft.Maui")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MAUI runtime detection
registry.Register<ClickActor>(echo); | ||
}); | ||
}) | ||
.AddTransient<IMauiInitializeService, AkkaInitializer>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Register a IMauiInitializeService
to start Akka hosted service.
This is the only way to start a service automatically during start-up in MAUI.
{ | ||
public void Initialize(IServiceProvider services) | ||
{ | ||
AkkaMauiSupport.StartAkka(services).GetAwaiter().GetResult(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Akka hosted service starter, we call the wrapped service here.
This reverts commit 0f8e2ea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds MAUI detection, but all of the actual code for making Akka.Hosting workable in MAUI will be located in its own repository here: https://github.com/akkadotnet/Akka.Hosting.Maui
Fixes #289
Changes
NOTES