Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example of using a lambda function to create a bridge between a settings class and IOptionsSnapshot<T>
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddOptions();
services.Configure<MyAppSettings>(Configuration.GetSection("MyAppSettings"));
// use a lambda to act as the bridge between requesting an instance of MyAppSettings but
// getting it from IOptionsSnapshot<MyAppSettings>
services.AddTransient<MyAppSettings>((opt) => opt.GetService<IOptionsSnapshot<MyAppSettings>>().Value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.