using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using RPG.Services.Core.Network; using RPG.Services.Core.Network.Command; using RPG.Services.Core.Options; using RPG.Services.Core.Session; namespace RPG.Services.Core.Extensions; public static class HostApplicationBuilderExtensions { public static IHostApplicationBuilder SetupRPGService(this IHostApplicationBuilder builder, bool stateless = false) where TService : RPGServiceBase where TCommandHandler : ServiceCommandHandler { IConfigurationSection serviceOptionsSection = builder.Configuration.GetRequiredSection("Service"); IConfigurationSection serviceNodesSection = builder.Configuration.GetRequiredSection("Nodes"); builder.Services.Configure(serviceOptionsSection) .Configure(serviceNodesSection); builder.Services.AddHostedService() .AddSingleton() .AddSingleton() .AddSingleton(); if (!stateless) builder.Services.AddSingleton(); return builder; } }