From b76d95e08dd5e36d56d9c9d6718552341e6ade4a Mon Sep 17 00:00:00 2001 From: Simon Gockner Date: Mon, 10 Feb 2020 10:41:33 +0100 Subject: [PATCH] - pass endpoint to startup via configuration and command line --- GBase.Server/GBaseServerSettings.cs | 2 ++ GBase.Server/Program.cs | 5 +++++ GBase.Server/Startup.cs | 10 +++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/GBase.Server/GBaseServerSettings.cs b/GBase.Server/GBaseServerSettings.cs index df7e2de..4297d2f 100644 --- a/GBase.Server/GBaseServerSettings.cs +++ b/GBase.Server/GBaseServerSettings.cs @@ -14,6 +14,8 @@ namespace GBase.Server { public class GBaseServerSettings : IGBaseServerSettings { + public const string ENDPOINT_STARTUP_CONFIGURATION_PREFIX = "--endpoint"; + private const string PROTOCOL_ARGUMENT_PREFIX = "-pr"; private const string IP_ADDRESS_ARGUMENT_PREFIX = "-ip"; private const string PORT_ARGUMENT_PREFIX = "-p"; diff --git a/GBase.Server/Program.cs b/GBase.Server/Program.cs index d695cf8..a203faf 100644 --- a/GBase.Server/Program.cs +++ b/GBase.Server/Program.cs @@ -9,6 +9,7 @@ using GBase.Logging.Interfaces; using GBase.Server.Interfaces; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; namespace GBase.Server { @@ -44,6 +45,10 @@ namespace GBase.Server WebHost.CreateDefaultBuilder() .UseKestrel(options => { options.Listen(serverSettings.IpAddress, serverSettings.Port); }) .UseUrls($"{serverSettings.Protocol.GetProtocolString()}{serverSettings.IpAddress}:{serverSettings.Port}") + .ConfigureAppConfiguration((hostingContext, config) => + { + config.AddCommandLine(new[] {GBaseServerSettings.ENDPOINT_STARTUP_CONFIGURATION_PREFIX, serverSettings.Endpoint}); + }) .UseStartup(); } } diff --git a/GBase.Server/Startup.cs b/GBase.Server/Startup.cs index 5f4e814..22c8827 100644 --- a/GBase.Server/Startup.cs +++ b/GBase.Server/Startup.cs @@ -7,12 +7,20 @@ using CoreWCF.Configuration; using GBase.Server.Interfaces; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace GBase.Server { public class Startup { + private readonly IConfiguration _configuration; + + public Startup(IConfiguration configuration) + { + _configuration = configuration; + } + public void ConfigureServices(IServiceCollection services) { services.AddServiceModelServices(); @@ -24,7 +32,7 @@ namespace GBase.Server { //TODO: Add needed service once it is implemented //builder.AddService<>(); - //builder.AddServiceEndpoint<>(new BasicHttpBinding(), $"/{IGBaseServerSettings.Endpoint}"); + //builder.AddServiceEndpoint<>(new BasicHttpBinding(), _configuration[GBaseServerSettings.ENDPOINT_STARTUP_CONFIGURATION_PREFIX]); }); } }