DocSpace-buildtools/common/services/ASC.TelegramService/Program.cs

76 lines
2.3 KiB
C#
Raw Normal View History

2022-02-17 11:16:52 +00:00
var options = new WebApplicationOptions
{
Args = args,
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
};
2020-11-02 16:27:08 +00:00
2022-02-17 11:16:52 +00:00
var builder = WebApplication.CreateBuilder(options);
2022-02-17 11:16:52 +00:00
builder.Host.UseWindowsService();
builder.Host.UseSystemd();
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
2020-11-02 16:27:08 +00:00
2022-02-17 11:16:52 +00:00
builder.WebHost.ConfigureKestrel((hostingContext, serverOptions) =>
{
var kestrelConfig = hostingContext.Configuration.GetSection("Kestrel");
if (!kestrelConfig.Exists()) return;
var unixSocket = kestrelConfig.GetValue<string>("ListenUnixSocket");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
if (!string.IsNullOrWhiteSpace(unixSocket))
{
2022-02-17 11:16:52 +00:00
unixSocket = string.Format(unixSocket, hostingContext.HostingEnvironment.ApplicationName.Replace("ASC.", "").Replace(".", ""));
2022-02-17 11:16:52 +00:00
serverOptions.ListenUnixSocket(unixSocket);
}
2022-02-17 11:16:52 +00:00
}
});
builder.Host.ConfigureAppConfiguration((hostContext, config) =>
{
var buided = config.Build();
var path = buided["pathToConf"];
if (!Path.IsPathRooted(path))
{
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
}
config.SetBasePath(path);
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
config
.AddInMemoryCollection(new Dictionary<string, string>
{
{"pathToConf", path }
}
)
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env}.json", true)
.AddJsonFile("storage.json")
.AddJsonFile("notify.json")
.AddJsonFile($"notify.{env}.json", true)
.AddJsonFile("kafka.json")
.AddJsonFile($"kafka.{env}.json", true)
.AddJsonFile("redis.json")
.AddJsonFile($"redis.{env}.json", true)
.AddEnvironmentVariables();
});
builder.Host.ConfigureNLogLogging();
2022-02-17 11:16:52 +00:00
var startup = new Startup(builder.Configuration, builder.Environment);
2022-02-17 11:16:52 +00:00
startup.ConfigureServices(builder.Services);
2022-02-17 11:16:52 +00:00
builder.Host.ConfigureContainer<ContainerBuilder>(containerBuilder =>
{
startup.ConfigureContainer(containerBuilder);
});
2022-02-17 11:16:52 +00:00
var app = builder.Build();
2022-02-17 11:16:52 +00:00
startup.Configure(app, app.Environment);
2022-02-17 11:16:52 +00:00
app.Run();