Skip to content

Instantly share code, notes, and snippets.

@diffused
Created May 20, 2019 23:53
Show Gist options
  • Save diffused/80b2e7f502d7bf0d1858016ada9e3176 to your computer and use it in GitHub Desktop.
Save diffused/80b2e7f502d7bf0d1858016ada9e3176 to your computer and use it in GitHub Desktop.
aspnet core typed config
{
"mysettings" : {
"value1": "Hello",
"value2": "World"
}
}
public class MySettings
{
public string Value1 { get; set; }
public string Value2 { get; set; }
}
public class Startup
{
public void ConfigureService(IServiceCollection services)
{
services.Configure<MySettings>(Configuration.GetSection("mysettings"));
}
}
public class MyService : IMyService
{
private readonly MySettings settings;
public MyService(IOptions<MySettings> mysettings)
{
this.settings = mySettings.Value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment