Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I read single KV value and also keep existing appsettings.json #125

Open
sebstepien opened this issue Feb 18, 2022 · 1 comment
Open

Comments

@sebstepien
Copy link

sebstepien commented Feb 18, 2022

I have a single key value that I want to read (consul) in alongside the appsettings.json file(not consul)
The value is a string representation of a boolean (true, false)
but when calling the injected _configuration["test-key"] from within the controller I am not getting any result.
Can I please have some guidance of what is potentially happening? I don't see any exeptions in the logs.

     public static IWebHostBuilder CreateWebHostBuilder(string[] args, CancellationTokenSource cancellationTokenSource) =>
          WebHost.CreateDefaultBuilder(args)
                 .ConfigureAppConfiguration(
                      (hostingContext, builder) =>
                      {
                          builder
                              .AddConsul("test-key",
                                  cancellationTokenSource.Token,
                                  options =>
                                  {
                                      options.ConsulConfigurationOptions =
                                          cco => { cco.Address = new Uri("http://127.0.0.1:8500"); };
                                      options.Parser = new SimpleConfigurationParser();
                                      options.Optional = false;
                                      options.ReloadOnChange = true;
                                      options.OnLoadException = exceptionContext =>
                                      {
                                          Console.WriteLine($"{exceptionContext.Exception}");
                                          exceptionContext.Ignore = true;

                                      };
                              })
                              .AddEnvironmentVariables();

                 })
                 .ConfigureKestrel(options => { options.Limits.MinResponseDataRate = null; })
                 .UseStartup<Startup>()
                 .UseNLog();

consul sturcture would be

test-key:test-value
features/feature1:true
features/feature2:false

How am I able to get just keys prefixed by features?

@Choc13
Copy link
Collaborator

Choc13 commented Mar 3, 2022

Hey, sorry for the slow reply. Are you still having this problem? Your setup looks OK at a first glance. Have you tried called GetDebugView on the IConfiguration. That should give you a clearer picture of what has actually been loaded into your config system at runtime. I know in the past when I've had issues like this it's been because I was accessing the configuration incorrectly, rather than it being a problem with loading the values from Consul or wherever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants