2024-01-18 22:13:40 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2024-01-21 15:34:19 +00:00
|
|
|
|
public static IHostApplicationBuilder SetupRPGService<TService, TCommandHandler>(this IHostApplicationBuilder builder, bool stateless = false)
|
2024-01-18 22:13:40 +00:00
|
|
|
|
where TService : RPGServiceBase
|
|
|
|
|
where TCommandHandler : ServiceCommandHandler
|
|
|
|
|
{
|
|
|
|
|
IConfigurationSection serviceOptionsSection = builder.Configuration.GetRequiredSection("Service");
|
|
|
|
|
IConfigurationSection serviceNodesSection = builder.Configuration.GetRequiredSection("Nodes");
|
|
|
|
|
|
|
|
|
|
builder.Services.Configure<RPGServiceOptions>(serviceOptionsSection)
|
|
|
|
|
.Configure<ServiceNodeOptions>(serviceNodesSection);
|
|
|
|
|
|
|
|
|
|
builder.Services.AddHostedService<TService>()
|
|
|
|
|
.AddSingleton<ServiceManager>()
|
|
|
|
|
.AddSingleton<ServiceBox>()
|
|
|
|
|
.AddSingleton<ServiceCommandHandler, TCommandHandler>();
|
|
|
|
|
|
2024-01-21 15:34:19 +00:00
|
|
|
|
if (!stateless) builder.Services.AddSingleton<SessionManager>();
|
|
|
|
|
|
2024-01-18 22:13:40 +00:00
|
|
|
|
return builder;
|
|
|
|
|
}
|
|
|
|
|
}
|