Created
March 24, 2018 07:39
-
-
Save configureappio/9730b44a163f68f6aeb1e99020ea560b to your computer and use it in GitHub Desktop.
An example of using a lambda function to create a bridge between a settings class and IOptionsSnapshot<T>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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