Get values from appsettings in .NET Core
Hello, I have this function in which I try to get a value from app settings file with the IConfiguration but it seems the method I got to use doesen't exist in this current context. How can I solve?
private readonly IConfiguration _configuration;
public APIKeyValidation(IConfiguration configuration)
{
_configuration = configuration;
}
public bool ValidateKey(string userApiKey)
{
if (userApiKey == null)
return false;
var apiKey = _configuration.GetValue<string>(ApiConstants.ApiKeyName);
if(apiKey == null || userApiKey != apiKey)
return false;
}
4 Replies
the error is that IConfiguration does not contain a definition for GetValue
appsettings.json:
src/Foo/FooOptions.cs:
src/Foo/FooServiceCollectionExtensions.cs:
Program.cs / Startup.cs:
Bar.cs:
thx
It's in some package
look up the method in the docs
it says which package it's from
I mean GetValue