public class Startup
{
public static AppSettings AppSettings { get; private set; }
private AppSettings _appSettings;
private IConfiguration Configuration { get; set; }
public void ConfigureServices(IServiceCollection services)
{
Configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build();
_appSettings = services
.BuildServiceProvider()
.GetService<AppSettings>();
AppSettings = _appSettings;
}
{
"Username": "username",
"Password": "password",
"AppUrl": "url"
}
public class AppSettings
{
public string AppUrl { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}
Configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build();
public Startup(IConfiguration configuration) =>
Configuration = configuration;
public IConfiguration Configuration { get; }
Configuration.Get<AppSettings>();