Skip to content

Instantly share code, notes, and snippets.

@configureappio
Created March 24, 2018 07:48
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 configureappio/324d635d52feb99dd3aa2013d025d294 to your computer and use it in GitHub Desktop.
Save configureappio/324d635d52feb99dd3aa2013d025d294 to your computer and use it in GitHub Desktop.
Example of a controller taking IOptionsSnapshot<T> as a parameter to the constructor
public class HomeController : Controller
{
private readonly MyAppSettings _settings;
public HomeController(IOptionsSnapshot<MyAppSettings> settings)
{
_settings = settings?.Value ?? throw new ArgumentNullException(nameof(settings));
}
public IActionResult Index()
{
return View(_settings);
}
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment