30 IConfiguration configuration,
32 ILogger<ServerPortProivder> logger)
34 ArgumentNullException.ThrowIfNull(configuration);
37 var usingDefaultPort = generalConfigurationOptions.Value.ApiPort ==
default;
38 if (!usingDefaultPort)
41 var httpEndpoint = configuration
42 .GetSection(
"Kestrel")
43 .GetSection(
"EndPoints")
47 ??
throw new InvalidOperationException(
"Missing required configuration option General:ApiPort!");
49 logger.LogWarning(
"The \"Kestrel\" configuration section is deprecated! Please set your API port using the \"General:ApiPort\" configuration option!");
51 var splits = httpEndpoint.Split(
":", StringSplitOptions.RemoveEmptyEntries);
52 var portString = splits.Last();
53 portString = portString.TrimEnd(
'/');
55 if (!UInt16.TryParse(portString, out var result))
56 throw new InvalidOperationException($
"Failed to parse HTTP EndPoint port: {httpEndpoint}");
58 this.generalConfigurationOptions.Value.ApiPort = result;