Since there's no ConfigurationManager class in .NET Core, now I have to set config in appsettings.json instead web.config
According to this blog post I have to set my configuration there, so I did like this:
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"Conexion": {
"name" : "empresas",
"connectionString": "Data Source=empresas;Initial Catalog=CATALMA; Integrated Security=True;",
"providerName": "System.Data.SqlClient"
}
}
I just writed that "Conexion".
Now I created in a ViewModels folder the following class:
public class ConexionConfig
{
public string name { get; set; }
public string connectionString { get; set; }
public string providerName { get; set; }
}
Now, In Startup.cs, in the ConfigureServices method, I have to add it by:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.Configure<ConexionConfig>(Configuration.GetSection("Conexion"));
services.AddMvc();
}
But unfortunately, I get the following error:
Argument 2: cannot convert from
'Microsoft.Extensions.Configuration.IConfigurationSection' to
'System.Action<ConexionConfig>'
What am I missing?