I am using asp.net-core v1.1.0 :)
I want to access the application settings values from a service class and not from a controller, my code is:
appsettings.json
// appsettings.json
{
"ImagesDBSettings": {
"Endpoint": "",
"Key": "",
}
}
Startup.cs
// Startup.cs
...
public void ConfigureServices(IServiceCollection services)
{
...
services.AddOptions();
services.Configure<ImagesDBSettings>(Configuration.GetSection("ImagesDBSettings"));
...
}
...
ImagesDBSettings.cs
// ImagesDBSettings.cs
public class ImagesDBSettings
{
public string Endpoint { get; set; }
public string Key { get; set; }
}
ImagesDBService.cs
// ImagesDBService.cs
public class ImagesDBService
{
private readonly ImagesDBSettings _settings;
public ImagesDBService(IOptions<ImagesDBSettings> settings)
{
_settings = settings.Value;
}
}
On compiling I get the error:
There is no argument given that corresponds to the required formal parameter 'settings' of 'ImagesDBService.ImagesDBService(IOptions)'
Any ideas on how to make the Dependency Injection Work?