1128
This commit is contained in:
73
BrokerApiServer/BrokerServiceExtensions.cs
Normal file
73
BrokerApiServer/BrokerServiceExtensions.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using ServerBase;
|
||||
using ServerCore;
|
||||
using System.Reflection;
|
||||
using static ControlCenter.NamedPipeHost.Extensions.ExtensionsForClient;
|
||||
|
||||
namespace BrokerApiServer;
|
||||
public static class BrokerServiceExtensions
|
||||
{
|
||||
public static void AddBrokerServerService(this IServiceCollection services, string[] args)
|
||||
{
|
||||
var server = new BrokerServerService();
|
||||
_ = server.Run(args);
|
||||
server.WaitOnStart().Wait();
|
||||
|
||||
var broker_server_config = AppBuilderExtensions.initBrokerServerConfig();
|
||||
|
||||
services.AddSingleton(server);
|
||||
services.AddSingleton<IServerLogic>(server.ServerLogic);
|
||||
services.AddSingleton<ServerConfig>(x => server.ServerLogic.getServerConfig());
|
||||
services.AddSingleton<DynamoDbClient>(x => server.ServerLogic.getDynamoDbClient());
|
||||
services.addCoreServices(broker_server_config);
|
||||
services.addInfraServices(broker_server_config);
|
||||
|
||||
services.AddHttpContextAccessor();
|
||||
services.AddEndpointsApiExplorer();
|
||||
services.AddControllers(options => { options.Filters.Add(new ResultExceptionFilter()); });
|
||||
services.AddHealthChecks();
|
||||
services.AddSwaggerGen(SwaggerSettingHelper.setSwaggerGen);
|
||||
|
||||
var useControlCenter = broker_server_config.ServiceType != nameof(ServiceType.Dev);
|
||||
if (useControlCenter)
|
||||
{
|
||||
var assemblies = new List<Assembly>(AppDomain.CurrentDomain.GetAssemblies());
|
||||
services.AddNamedPipelineClientManager(assemblies, ServerControlCenter.ServerType.BrokerApi,
|
||||
nameof(ServiceCategory.Caliverse), NetworkHelper.getEthernetLocalIPv4(), server.Options.Port);
|
||||
}
|
||||
}
|
||||
|
||||
public static void UseBrokerServerService(this WebApplication app)
|
||||
{
|
||||
var server = app.Services.GetRequiredService<BrokerServerService>();
|
||||
app.UseCors("Everything");
|
||||
app.UseHttpsRedirection();
|
||||
app.UseMiddleware<ResultLoggingMiddleware>();
|
||||
app.UseAuthorization();
|
||||
app.UseRouting();
|
||||
app.MapControllers();
|
||||
if (server.Options.UseSwagger)
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.MapHealthChecks("/healthcheck");
|
||||
app.metadataMangerInit();
|
||||
app.validateRepoConnections();
|
||||
|
||||
var useControlCenter = server.ServerLogic.getServerConfig().ServiceType != nameof(ServiceType.Dev);
|
||||
if (useControlCenter)
|
||||
{
|
||||
app.UseNamedPipelineClientManager();
|
||||
}
|
||||
|
||||
// 호스트 시작 종료 콜백 처리
|
||||
var logger = Log.getLogger();
|
||||
var serviceProvider = app.Services;
|
||||
serviceProvider.GetRequiredService<IHostApplicationLifetime>().ApplicationStarted.Register(() =>
|
||||
{
|
||||
logger.Info($"Broker Api Server Service Started");
|
||||
});
|
||||
serviceProvider.GetRequiredService<IHostApplicationLifetime>().ApplicationStopped.Register(Log.shutdown);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user