我有3个完全相同的项目的Web应用程序,但它们正在访问3个结构完全相同的不同数据库。我想用OAuth和Microsoft身份创建Api。我的问题是-我可以有一个项目(web api)可以为3个不同的数据库创建3个owin上下文,这样我就不必发布3个完全相同的项目。
从技术上讲,您可以拥有多个数据库,只需要通过connectionString为每种情况编程配置。
MyDbContext:
protected override void OnConfiguring( DbContextOptionsBuilder optionsBuilder )
{
optionsBuilder.UseSqlServer( "<Your Connection String Here>" );
}
Startup.ConfigureServices:
public IServiceProvider ConfigureServices( IServiceCollection services )
{
var configuration = new Configuration().AddJsonFile( "MyConfig.json" );
services.AddEntityFramework( configuration )
// ...
}
有关该主题的另一个网址,可以帮助您: