I need to setup a few dependencies (services) in the ConfigureServices
method in an ASP.NET Core 1.0 web application.
The issue is that based on the new
That is the way you can get the typed settings from appSettings.json
right in ConfigureServices
method:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.Configure(Configuration.GetSection(nameof(MySettings)));
services.AddSingleton(Configuration);
// ...
var settings = Configuration.GetSection(nameof(MySettings)).Get();
int maxNumberOfSomething = settings.MaxNumberOfSomething;
// ...
}
// ...
}