I have the configuration in appsettings.json as follows:
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"GatewaySettings": {
"DBName": "StorageDb.sqlite",
"DBSize": "100"
}
}
Here is the class to represent the configuration data
public class GatewaySettings
{
public string DBName { get; set; }
public string DBSize { get; set; }
}
Configured service as follows:
services.AddSingleton(Configuration.GetSection("GatewaySettings").Get<GatewaySettings>());
but I'm getting this error:
Value cannot be null. Parameter name: implementationInstance'
Code:
public class SqlRepository
{
private readonly GatewaySettings _myConfiguration;
public SqlRepository(GatewaySettings settings)
{
_myConfiguration = settings;
}
}
Dependency injection code:
var settings = new IOTGatewaySettings();
builder.Register(c => new SqlRepository(settings))
Background
I am hosting ASPNET CORE application as windows service, and .NET Framework is 4.6.1
Note: similar question appears here but there is no solution provided.System.ArgumentNullException: Value cannot be null, Parameter name: implementationInstance
IOptions<T>instead Reference Configuration in ASP.NET Core