.net 核心 webapi 应用程序与 entityframeworkcore。试图弄清楚除了 dbcontext 之外,如何将额外的连接字符串传递给数据访问库类。请参阅下面的** dbcontext ** 是我想要做的。
启动.cs
var SqlConnection = Configuration.GetConnectionString("SQLConnection");
var BlobConnection = Configuration.GetConnectionString("BlobConnection");
services.AddEntityFramework()
.AddEntityFrameworkSqlServer()
.AddDbContext<VISTrackingContext>(options => options.UseSqlServer(SqlConnection,
sqlServerOptionsAction: sqlOptions =>
{
sqlOptions.EnableRetryOnFailure(maxRetryCount: 5,
maxRetryDelay: TimeSpan.FromSeconds(5),
errorNumbersToAdd: null);
}));
services.AddScoped<IDataManager>(c => new DataManager(**_dbcontext**, BlobConnection));
public FileController(IDataManager manager)
{
_datamanager = manager;
}
public DataManager(VISTrackingContext dbcontext, string blobconnection)
{
_dbcontext = dbcontext;
_blobconnection = blobconnectionstring;
}
这可以做到吗?还是有另一种方法通过上下文对象本身注入额外的连接字符串?我看到很多关于这样做的评论和选项,但没有一种方法同时处理上下文和传递给存储库对象的连接字符串。