2022-01-31 11:35:16 +00:00
|
|
|
|
using Microsoft.Extensions.Hosting.WindowsServices;
|
2021-08-31 09:40:28 +00:00
|
|
|
|
|
2022-01-31 11:35:16 +00:00
|
|
|
|
var options = new WebApplicationOptions
|
|
|
|
|
{
|
|
|
|
|
Args = args,
|
|
|
|
|
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
|
|
|
|
|
};
|
2021-08-31 09:40:28 +00:00
|
|
|
|
|
2022-01-31 11:35:16 +00:00
|
|
|
|
var builder = WebApplication.CreateBuilder(options);
|
2021-08-31 09:40:28 +00:00
|
|
|
|
|
2022-01-31 11:35:16 +00:00
|
|
|
|
builder.Host.UseWindowsService();
|
|
|
|
|
builder.Host.UseSystemd();
|
|
|
|
|
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
2020-06-03 09:15:05 +00:00
|
|
|
|
|
2022-01-31 11:35:16 +00:00
|
|
|
|
builder.WebHost.ConfigureKestrel((hostingContext, serverOptions) =>
|
2020-06-03 09:15:05 +00:00
|
|
|
|
{
|
2022-01-31 11:35:16 +00:00
|
|
|
|
var kestrelConfig = hostingContext.Configuration.GetSection("Kestrel");
|
|
|
|
|
|
|
|
|
|
if (!kestrelConfig.Exists()) return;
|
|
|
|
|
|
|
|
|
|
var unixSocket = kestrelConfig.GetValue<string>("ListenUnixSocket");
|
|
|
|
|
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
2021-08-31 09:40:28 +00:00
|
|
|
|
{
|
2022-01-31 11:35:16 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(unixSocket))
|
2021-08-31 09:40:28 +00:00
|
|
|
|
{
|
2022-01-31 11:35:16 +00:00
|
|
|
|
unixSocket = string.Format(unixSocket, hostingContext.HostingEnvironment.ApplicationName.Replace("ASC.", "").Replace(".", ""));
|
2021-08-31 09:40:28 +00:00
|
|
|
|
|
2022-01-31 11:35:16 +00:00
|
|
|
|
serverOptions.ListenUnixSocket(unixSocket);
|
2021-04-23 13:54:12 +00:00
|
|
|
|
}
|
2022-01-31 11:35:16 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2021-04-23 13:54:12 +00:00
|
|
|
|
|
2022-01-31 11:35:16 +00:00
|
|
|
|
builder.Host.ConfigureAppConfiguration((hostContext, config) =>
|
|
|
|
|
{
|
|
|
|
|
var buided = config.Build();
|
|
|
|
|
|
|
|
|
|
var path = buided["pathToConf"];
|
2021-04-23 13:54:12 +00:00
|
|
|
|
|
2022-01-31 11:35:16 +00:00
|
|
|
|
if (!Path.IsPathRooted(path))
|
|
|
|
|
{
|
|
|
|
|
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
|
2020-06-03 09:15:05 +00:00
|
|
|
|
}
|
2022-01-31 11:35:16 +00:00
|
|
|
|
|
|
|
|
|
config.SetBasePath(path);
|
|
|
|
|
|
|
|
|
|
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
|
|
|
|
|
config
|
|
|
|
|
.AddJsonFile("appsettings.json")
|
|
|
|
|
.AddJsonFile($"appsettings.{env}.json", true)
|
|
|
|
|
.AddJsonFile("storage.json")
|
|
|
|
|
.AddJsonFile("notify.json")
|
|
|
|
|
.AddJsonFile($"notify.{env}.json", true)
|
|
|
|
|
.AddJsonFile("backup.json")
|
|
|
|
|
.AddJsonFile("kafka.json")
|
|
|
|
|
.AddJsonFile($"kafka.{env}.json", true)
|
|
|
|
|
.AddJsonFile("redis.json")
|
|
|
|
|
.AddJsonFile($"redis.{env}.json", true)
|
|
|
|
|
.AddEnvironmentVariables()
|
|
|
|
|
.AddCommandLine(args)
|
|
|
|
|
.AddInMemoryCollection(new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{"pathToConf", path }
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
builder.Host.ConfigureNLogLogging();
|
|
|
|
|
|
|
|
|
|
var startup = new Startup(builder.Configuration, builder.Environment);
|
|
|
|
|
|
|
|
|
|
startup.ConfigureServices(builder.Services);
|
|
|
|
|
|
|
|
|
|
builder.Host.ConfigureContainer<ContainerBuilder>(containerBuilder =>
|
|
|
|
|
{
|
|
|
|
|
startup.ConfigureContainer(containerBuilder);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
startup.Configure(app, app.Environment);
|
|
|
|
|
|
|
|
|
|
app.Run();
|