public static IWebHostBuilder AddDiscoveryServiceOptions(this IWebHostBuilder webHostBuilder, IConfiguration configuration, int?runPort = null) { if (webHostBuilder == null) { throw new ArgumentNullException(nameof(webHostBuilder)); } List <string> urls = new List <string> (); ServiceConfig serviceConfig = new ServiceConfig(); configuration.Bind("AppConfig", serviceConfig); if (runPort != null) { urls.Add($"http://*:{runPort}"); serviceConfig.serviceUri = new Uri($"http://localhost:{runPort}"); } else { var baseurl = UriConfiguration.GetUri(); urls.Add($"http://*:{baseurl.Port}"); serviceConfig.serviceUri = baseurl; } webHostBuilder.UseUrls(urls.ToArray()); return(webHostBuilder.ConfigureServices(services => { services.Configure <ServiceConfig>(options => { options.serviceName = serviceConfig.serviceName; options.serviceUri = serviceConfig.serviceUri; options.version = serviceConfig.version; options.Tags = serviceConfig.Tags; }); })); }
public Uri GetUri(string serviceName, string version) { return(UriConfiguration.GetUri()); }