4using System.Threading.Tasks;
6using Microsoft.AspNetCore.Hosting;
7using Microsoft.AspNetCore.Server.Kestrel.Core;
8using Microsoft.Extensions.Configuration;
9using Microsoft.Extensions.DependencyInjection;
10using Microsoft.Extensions.Hosting;
11using Microsoft.Extensions.Logging;
42 IOManager = ioManager ??
throw new ArgumentNullException(nameof(ioManager));
47#pragma warning disable CA1506
48 public async Task<IServer>
CreateServer(
string[] args,
string updatePath, CancellationToken cancellationToken)
50 ArgumentNullException.ThrowIfNull(args);
53 if (!args.Any(arg => arg.Contains(
"hostBuilder:reloadConfigOnChange", StringComparison.OrdinalIgnoreCase))
54 && String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(
"hostBuilder__reloadConfigOnChange")))
57 args =
new string[oldArgs.Length + 1];
58 Array.Copy(oldArgs, args, oldArgs.Length);
59 args[oldArgs.Length] =
"--hostBuilder:reloadConfigOnChange=false";
63 IHostBuilder CreateDefaultBuilder() => Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
64 .ConfigureAppConfiguration((context, builder) =>
66 builder.SetBasePath(basePath);
68 builder.AddYamlFile(
"appsettings.yml", optional:
true, reloadOnChange:
false)
69 .AddYamlFile($
"appsettings.{context.HostingEnvironment.EnvironmentName}.yml", optional:
true, reloadOnChange:
false);
73 var environmentJsonConfig = builder.Sources[2];
74 var envConfig = builder.Sources[3];
79#error Validate this monstrosity works on current .NET
81 IConfigurationSource cmdLineConfig, baseYmlConfig, environmentYmlConfig;
85 baseYmlConfig = builder.Sources[4];
86 environmentYmlConfig = builder.Sources[5];
90 cmdLineConfig = builder.Sources[4];
91 baseYmlConfig = builder.Sources[5];
92 environmentYmlConfig = builder.Sources[6];
95 builder.Sources[2] = baseYmlConfig;
96 builder.Sources[3] = environmentJsonConfig;
97 builder.Sources[4] = environmentYmlConfig;
98 builder.Sources[5] = envConfig;
100 if (cmdLineConfig !=
null)
102 builder.Sources[6] = cmdLineConfig;
106 var setupWizardHostBuilder = CreateDefaultBuilder()
110 using (var setupHost = setupWizardHostBuilder.Build())
113 await setupHost.RunAsync(cancellationToken);
117 postSetupServices.
Logger.LogInformation(
"Shutting down due to only running setup wizard.");
122 var hostBuilder = CreateDefaultBuilder()
123 .ConfigureWebHost(webHostBuilder =>
125 .UseKestrel(kestrelOptions =>
127 var serverPortProvider = kestrelOptions.ApplicationServices.GetRequiredService<
IServerPortProvider>();
128 kestrelOptions.ListenAnyIP(
129 serverPortProvider.HttpApiPort,
130 listenOptions => listenOptions.Protocols = HttpProtocols.Http1AndHttp2);
135 .SuppressStatusMessages(
true)
137 TimeSpan.FromMinutes(
140 if (updatePath !=
null)
141 hostBuilder.UseContentRoot(
145 return new Server(hostBuilder, updatePath);
147#pragma warning restore CA1506
Implementation of IServerFactory.
IIOManager IOManager
The IIOManager for the IServerFactory.
readonly IAssemblyInformationProvider assemblyInformationProvider
The IAssemblyInformationProvider for the ServerFactory.
async Task< IServer > CreateServer(string[] args, string updatePath, CancellationToken cancellationToken)
Create a IServer. A Task<TResult> resulting in a new IServer if it should be run, null otherwise.
Provides access to the server's HttpApiPort.
Interface for using filesystems.
string ResolvePath()
Retrieve the full path of the current working directory.
string GetDirectoryName(string path)
Gets the directory portion of a given path .
Set of objects needed to configure an Core.Application.
GeneralConfiguration GeneralConfiguration
The Configuration.GeneralConfiguration.
ILogger< TLoggerType > Logger
The ILogger.
SetupWizardMode
Determines if the SetupWizard will run.