4using Microsoft.Extensions.Configuration;
5using Microsoft.Extensions.Logging;
6using Microsoft.Extensions.Options;
30 IOptions<GeneralConfiguration> generalConfigurationOptions,
31 IConfiguration configuration,
32 ILogger<ServerPortProivder> logger)
34 generalConfiguration = generalConfigurationOptions?.Value ??
throw new ArgumentNullException(nameof(generalConfigurationOptions));
35 ArgumentNullException.ThrowIfNull(configuration);
37 var httpEndpoint = configuration
38 .GetSection(
"Kestrel")
39 .GetSection(
"EndPoints")
45 throw new InvalidOperationException(
"Missing required configuration option General:ApiPort!");
50 logger.LogWarning(
"The \"Kestrel\" configuration section is deprecated! Please set your API port using the \"General:ApiPort\" configuration option!");
52 var splits = httpEndpoint.Split(
":", StringSplitOptions.RemoveEmptyEntries);
53 var portString = splits.Last();
54 portString = portString.TrimEnd(
'/');
56 if (!UInt16.TryParse(portString, out var result))
57 throw new InvalidOperationException($
"Failed to parse HTTP EndPoint port: {httpEndpoint}");
59 generalConfiguration.ApiPort = result;
General configuration options.
ushort ApiPort
The port the TGS API listens on.
readonly GeneralConfiguration generalConfiguration
The GeneralConfiguration for the ServerPortProivder.
ushort HttpApiPort
The port the server listens on.
ServerPortProivder(IOptions< GeneralConfiguration > generalConfigurationOptions, IConfiguration configuration, ILogger< ServerPortProivder > logger)
Initializes a new instance of the ServerPortProivder class.
Provides access to the server's HttpApiPort.