mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
|
|
using Akka.Actor;
|
|
using Akka.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
namespace Management.Services;
|
|
|
|
|
|
public class AkkaService(
|
|
IServiceProvider serviceProvider,
|
|
IHostApplicationLifetime appLifetime,
|
|
IConfiguration configuration
|
|
) : IHostedService
|
|
{
|
|
private ActorSystem? actorSystem;
|
|
private readonly IConfiguration configuration = configuration;
|
|
private readonly IServiceProvider serviceProvider = serviceProvider;
|
|
private readonly IHostApplicationLifetime applicationLifetime = appLifetime;
|
|
public IActorRef? CanvasQueueActor { get; private set; }
|
|
public IActorRef? StorageActor { get; private set; }
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
var bootstrap = BootstrapSetup.Create();
|
|
var dependencyInjectionSetup = DependencyResolverSetup.Create(serviceProvider);
|
|
|
|
var mergedSystemSetup = bootstrap.And(dependencyInjectionSetup);
|
|
|
|
actorSystem = ActorSystem.Create("canavas-management-actor-system", mergedSystemSetup);
|
|
|
|
var canvasQueueProps = DependencyResolver.For(actorSystem).Props<CanvasQueueActor>();
|
|
CanvasQueueActor = actorSystem.ActorOf(canvasQueueProps, "canvasQueue");
|
|
var localStorageProps = DependencyResolver.For(actorSystem).Props<LocalStorageActor>();
|
|
StorageActor = actorSystem.ActorOf(localStorageProps, "localStorage");
|
|
|
|
// crash if the actor system crashes, awaiting never returns...
|
|
actorSystem.WhenTerminated.ContinueWith(tr =>
|
|
{
|
|
applicationLifetime.StopApplication();
|
|
});
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
|
|
|
|
// public void Tell(object message)
|
|
// {
|
|
// userSessionSupervisor?.Tell(message);
|
|
// }
|
|
|
|
// public Task<T> Ask<T>(object message)
|
|
// {
|
|
// return userSessionSupervisor.Ask<T>(message);
|
|
// }
|
|
|
|
}
|