From ef4ebf738ad2a54583f5f605198fbcc1d9137e78 Mon Sep 17 00:00:00 2001 From: xljiulang <366193849@qq.com> Date: Mon, 19 Sep 2022 19:33:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=92=E6=96=A5=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub/Program.cs | 6 ++---- FastGithub/ServiceExtensions.cs | 11 ++++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/FastGithub/Program.cs b/FastGithub/Program.cs index 6c2e9c3..0256fdc 100644 --- a/FastGithub/Program.cs +++ b/FastGithub/Program.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Builder; using System; using System.IO; -using System.Linq; namespace FastGithub { @@ -15,8 +14,7 @@ namespace FastGithub public static void Main(string[] args) { ConsoleUtil.DisableQuickEdit(); - - var contentRoot = Path.GetDirectoryName(Environment.GetCommandLineArgs().First()); + var contentRoot = Path.GetDirectoryName(Environment.ProcessPath); if (string.IsNullOrEmpty(contentRoot) == false) { Environment.CurrentDirectory = contentRoot; @@ -26,7 +24,7 @@ namespace FastGithub Args = args, ContentRootPath = contentRoot }; - CreateWebApplication(options).Run(); + CreateWebApplication(options).Run(singleton: true); } /// diff --git a/FastGithub/ServiceExtensions.cs b/FastGithub/ServiceExtensions.cs index 088d053..669cb6f 100644 --- a/FastGithub/ServiceExtensions.cs +++ b/FastGithub/ServiceExtensions.cs @@ -1,4 +1,5 @@ using FastGithub.DomainResolve; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -38,24 +39,24 @@ namespace FastGithub /// /// public static IHostBuilder UseWindowsService(this IHostBuilder hostBuilder) - { + { return WindowsServiceLifetimeHostBuilderExtensions.UseWindowsService(hostBuilder); } /// /// 运行主机 /// - /// + /// /// - public static void Run(this IHost host, bool singleton = true) + public static void Run(this WebApplication app, bool singleton) { - var logger = host.Services.GetRequiredService().CreateLogger(nameof(FastGithub)); + var logger = app.Services.GetRequiredService().CreateLogger(nameof(FastGithub)); if (UseCommand(logger) == false) { using var mutex = new Mutex(true, "Global\\FastGithub", out var firstInstance); if (singleton == false || firstInstance) { - HostingAbstractionsHostExtensions.Run(host); + app.Run(); } else {