I have following the SteelToe
documentation for accessing configuration data from my config server. https://steeltoe.io/docs/steeltoe-configuration/#2-2-5-access-configuration-data
Inside my TestController
I setup the configuration global variable in the constructor. However when I check the variable _config
it has no value basically null
value.
I not sure if I need to physically map the values to the CustomConfig
class properties? As this is not specified in the documentations.
Startup.cs
public class CustomConfig {
public string Message { get; set; }
}
public Startup(IConfiguration configuration, IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddConfiguration(configuration)
.AddCloudFoundry()
.AddEnvironmentVariables();
this.Configuration = builder.Build();
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CustomConfig>(Configuration.GetSection("spring:cloud:config:uri"));
}
Program.cs
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args)
.Build()
.Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.AddConfigServer()
.UseStartup<Startup>();
}
}
Controller.cs
public class TestController : ControllerBase
{
private Startup.CustomConfig _config;
public TestController(IOptions<Startup.CustomConfig> configSettings)
{
_config = configSettings.value; // this is null
}
}
There are several things happening here that are in your way:
Configure