2

In this thread I was able to setup my simple console application using ASP.NET CORE's configuration system.

The code is as simple as:

static void Main(string[] args)
{
    string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

    var configuration = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
        .AddJsonFile($"appsettings.{environment}.json", optional: false)
        .AddEnvironmentVariables();

    config = configuration.Build();


    var serviceProvider = new ServiceCollection()
        .AddSingleton<IConfiguration>(config)
        .AddDiscoveryClient(config)
        .BuildServiceProvider();

    Console.WriteLine(config["Test"]);

    Console.Read();
}

However, since the application does not use IApplicationBuilder, I cannot invoke the .UseDiscoveryClient() method. I end up receiving an error on .AddDiscoveryClient(config):

"Discovery client type UNKNOWN, check configuration"

Is there a work around this? We would like to experiment using console applications with our Spring Cloud Config server. If there is no way to do it with Steeltoe, feel free to inform with other libraries that do.

Rafael
  • 727
  • 13
  • 30
  • Are you trying to find/register services with a service discovery server (Eureka or Consul), add app configuration from a remote server (Spring Cloud Config) or both? – Tim Jul 26 '19 at 11:27
  • I am trying to pull configurations from Spring Cloud Config – Rafael Jul 26 '19 at 14:17

2 Answers2

2

The extension methods AddDiscoveryClient and UseDiscoveryClient are for use with Steeltoe service discovery. The error message you're seeing is due to Steeltoe not knowing which type of service registry your app should be a client of (ie: "client type UNKNOWN").

You only wish to access Spring Cloud Config server, so you don't need either of those methods. You can add the ConfigServerConfigurationProvider to you your config builder with .AddConfigServer.

Tim
  • 2,587
  • 13
  • 18
  • I don't see .AddConfigServer. I have the Steeltoe.Extensions.Configuration on code and I am on .NET CORE 2.2.0 – Rafael Jul 26 '19 at 15:11
  • 1
    The extension is included in the package `Steeltoe.Extensions.Configuration.ConfigServerBase`. You should add it to the chain either before or after `AddEnvironmentVariables()`, depending on whether you want to allow overriding values with environment variables. – Tim Jul 26 '19 at 17:46
0

you should add "appName" and "hostname" in the appsetting.json under instance