Created
May 20, 2019 23:53
-
-
Save diffused/80b2e7f502d7bf0d1858016ada9e3176 to your computer and use it in GitHub Desktop.
aspnet core typed config
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
{ | |
"mysettings" : { | |
"value1": "Hello", | |
"value2": "World" | |
} | |
} |
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 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