add support WindowsService/systemd for IHostBuilder

This commit is contained in:
Alexey Bannov 2021-04-27 19:25:03 +03:00
parent d97928fd37
commit 7f436ef3cb
6 changed files with 41 additions and 31 deletions

View File

@ -5,6 +5,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
</ItemGroup>

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Autofac.Extensions.DependencyInjection;
@ -12,19 +13,23 @@ namespace ASC.Calendar
{
public class Program
{
public static void Main(string[] args)
public async static Task Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
var host = CreateHostBuilder(args).Build();
await host.RunAsync();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSystemd()
.UseWindowsService()
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.ConfigureAppConfiguration((hostingContext, config) =>
.ConfigureAppConfiguration((hostingContext, config) =>
{
var buided = config.Build();
var path = buided["pathToConf"];

View File

@ -1,31 +1,29 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5023",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"Kestrel WebServer": {
"commandName": "Project",
"launchBrowser": false,
"launchUrl": "http://localhost:5023/api/2.0/calendar/info",
"environmentVariables": {
"$STORAGE_ROOT": "../../../Data",
"log__dir": "../../../Logs",
"log__name": "calendar",
"ASPNETCORE_URLS": "http://localhost:5023",
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ASC.Calendar": {
"commandName": "Project",
"WSL 2 : Ubuntu 20.04": {
"commandName": "WSL2",
"launchBrowser": false,
"launchUrl": "http://localhost:5023/api/2.0/calendar/info",
"environmentVariables": {
"$STORAGE_ROOT": "../../../Data",
"log__dir": "../../../Logs",
"log__name": "calendar",
"ASPNETCORE_URLS": "http://localhost:5023",
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5023"
"distributionName": "Ubuntu-20.04"
}
}
}

View File

@ -5,6 +5,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
</ItemGroup>

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Autofac.Extensions.DependencyInjection;
@ -12,13 +13,17 @@ namespace ASC.Mail
{
public class Program
{
public static void Main(string[] args)
public async static Task Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
var host = CreateHostBuilder(args).Build();
await host.RunAsync();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSystemd()
.UseWindowsService()
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webBuilder =>
{

View File

@ -1,31 +1,29 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5022",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"Kestrel WebServer": {
"commandName": "Project",
"launchBrowser": false,
"launchUrl": "http://localhost:5022/api/2.0/mail/info",
"environmentVariables": {
"$STORAGE_ROOT": "../../../Data",
"log__dir": "../../../Logs",
"log__name": "mail",
"ASPNETCORE_URLS": "http://localhost:5022",
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ASC.Mail": {
"commandName": "Project",
"WSL 2 : Ubuntu 20.04": {
"commandName": "WSL2",
"launchBrowser": false,
"launchUrl": "http://localhost:5022/api/2.0/mail/info",
"environmentVariables": {
"$STORAGE_ROOT": "../../../Data",
"log__dir": "../../../Logs",
"log__name": "mail",
"ASPNETCORE_URLS": "http://localhost:5022",
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5022"
"distributionName": "Ubuntu-20.04"
}
}
}