0

entityframeworkcore を使用した .net コア webapi アプリケーション。dbcontext に加えて、追加の接続文字列をデータ アクセス ライブラリ クラスに渡す方法を見つけようとしています。以下の ** dbcontext ** を参照してください。

startup.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;
        }

これはできますか?または、コンテキスト オブジェクト自体を介して追加の接続文字列を挿入する別の方法はありますか? これを行うことについて多くのコメントとオプションがありますが、リポジトリ オブジェクトに渡されるコンテキストと接続文字列の両方を処理するアプローチはありません。

4

2 に答える 2