Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Configuration.GetConnectionString() issue

$
0
0

public void ConfigureServices(IServiceCollection services) { //数据库配置 //services.AddDbContextPool(f => f.UseMySQL(Configuration.GetConnectionString("EntityContext"))); services.AddDbContextPool(options => { options.UseMySQL(Configuration.GetConnectionString("EntityContext"));  }); services.AddTransient<IDbContext, EntityContext>(); services.AddTransient<IAccountService, AccountService>(); services.AddTransient<ICategoryService, CategoryService>(); services.AddTransient(typeof(IRepository<>), typeof(EfRepository<>)); // Add Kendo UI services to the services container services.AddKendo(); // Add framework services. services.AddMvc() // Maintain property names during serialization. See: // https://github.com/aspnet/Announcements/issues/194 .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()); }

when I run it, throw value is null: Configuration.GetConnectionString("EntityContext");

appsetings.json:

"ConnectionString": {
"EntityContext": "server=localhost;port=3306;database=****;uid=***;password=*****;"
}


Viewing all articles
Browse latest Browse all 9386

Trending Articles