mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 23:58:31 -06:00
switched to xunit
This commit is contained in:
60
Management/Services/AkkaService.cs
Normal file
60
Management/Services/AkkaService.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
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);
|
||||
// }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user