| | 1 | | using System; |
| | 2 | | using Akka.Actor; |
| | 3 | | using Akka.Actor.Setup; |
| | 4 | | using Akka.Configuration; |
| | 5 | | using Akka.DependencyInjection; |
| | 6 | | using SeungYongShim.Akka; |
| | 7 | | using SeungYongShim.Akka.DependencyInjection.Abstractions; |
| | 8 | |
|
| | 9 | | namespace Microsoft.Extensions.DependencyInjection |
| | 10 | | { |
| | 11 | | public static class AddAkkaExtensions |
| | 12 | | { |
| | 13 | | internal static IServiceCollection AddAkka(this IServiceCollection services, |
| | 14 | | string actorSystemName, |
| | 15 | | string hocon, |
| | 16 | | Func<Config, Config> hoconFunc, |
| | 17 | | Action<IServiceProvider, ActorSystem> startAction = null) => |
| 8 | 18 | | services.AddSingleton(sp => |
| 16 | 19 | | { |
| 16 | 20 | | return BootstrapSetup.Create() |
| 16 | 21 | | .WithConfig(hoconFunc(ConfigurationFactory.ParseString(hocon))) |
| 16 | 22 | | .And(DependencyResolverSetup.Create(sp)); |
| 16 | 23 | | }) |
| 16 | 24 | | .AddSingleton<AkkaHostedServiceStart>(sp => sys => |
| 24 | 25 | | { |
| 24 | 26 | | startAction?.Invoke(sp, sys); |
| 24 | 27 | | }) |
| 8 | 28 | | .AddSingleton(typeof(IPropsFactory<>), typeof(PropsFactory<>)) |
| 8 | 29 | | .AddHostedService<AkkaHostedService>() |
| 9 | 30 | | .AddSingleton(sp => ActorSystem.Create(actorSystemName, sp.GetService<ActorSystemSetup>())); |
| | 31 | | } |
| | 32 | | } |