Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created April 19, 2021 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/7bd9da8cb909397cdaec473f0f5f5be1 to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/7bd9da8cb909397cdaec473f0f5f5be1 to your computer and use it in GitHub Desktop.
GetValue to read the configuration settings
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IConfiguration configuration;
public HomeController(ILogger<HomeController> logger, IConfiguration configuration)
{
_logger = logger;
this.configuration = configuration;
}
public IActionResult Index()
{
var mode = configuration.GetValue<string>("Mode", "default-mode");
var defaultLogLevel = configuration.GetValue<string>("Logging:LogLevel:Default", "Info");
var firstSubjectFromArray = configuration.GetValue<string>("MailFeature:0:Subject", "unknown");
return View();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment