เนื่องจากไม่มีคลาส ConfigurationManager ใน .NET Core ตอนนี้ฉันต้องตั้งค่า config ใน appsettings.json แทน web.config
ตามโพสต์บล็อก นี้ ฉันต้องตั้งค่า กำหนดค่าที่นั่น ดังนั้นฉันจึงทำสิ่งนี้:
{
"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"
}
}
ฉันเพิ่งเขียนว่า "Conexion"
ตอนนี้ฉันสร้างคลาสต่อไปนี้ในโฟลเดอร์ ViewModels:
public class ConexionConfig
{
public string name { get; set; }
public string connectionString { get; set; }
public string providerName { get; set; }
}
ตอนนี้ใน Startup.cs ในวิธี ConfigureServices ฉันต้องเพิ่มโดย:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.Configure<ConexionConfig>(Configuration.GetSection("Conexion"));
services.AddMvc();
}
แต่น่าเสียดายที่ฉันได้รับข้อผิดพลาดต่อไปนี้:
Argument 2: cannot convert from
'Microsoft.Extensions.Configuration.IConfigurationSection' to
'System.Action<ConexionConfig>'
ฉันพลาดอะไรไป?