|
|
@ -13,6 +13,7 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using System; |
|
|
|
using System.Data.SqlClient; |
|
|
|
using System.Reflection; |
|
|
|
|
|
|
@ -39,21 +40,35 @@ |
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services) |
|
|
|
{ |
|
|
|
//Using the same SqlConnection for both DbContexts (CatalogContext and IntegrationEventLogContext)
|
|
|
|
var sqlConnection = new SqlConnection(Configuration["ConnectionString"]); |
|
|
|
|
|
|
|
services.AddDbContext<CatalogContext>(c => |
|
|
|
services.AddDbContext<CatalogContext>(options => |
|
|
|
{ |
|
|
|
c.UseSqlServer(sqlConnection); |
|
|
|
options.UseSqlServer(sqlConnection, |
|
|
|
sqlServerOptionsAction: sqlOptions => |
|
|
|
{ |
|
|
|
sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name); |
|
|
|
//Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
|
|
|
|
sqlOptions.EnableRetryOnFailure(maxRetryCount: 5, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); |
|
|
|
}); |
|
|
|
// Changing default behavior when client evaluation occurs to throw.
|
|
|
|
// Default in EF Core would be to log a warning when client evaluation is performed.
|
|
|
|
c.ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)); |
|
|
|
options.ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)); |
|
|
|
//Check Client vs. Server evaluation: https://docs.microsoft.com/en-us/ef/core/querying/client-eval
|
|
|
|
}); |
|
|
|
|
|
|
|
services.AddDbContext<IntegrationEventLogContext>(c => |
|
|
|
services.AddDbContext<IntegrationEventLogContext>(options => |
|
|
|
{ |
|
|
|
c.UseSqlServer(sqlConnection, b => b.MigrationsAssembly("Catalog.API")); |
|
|
|
c.ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)); |
|
|
|
options.UseSqlServer(sqlConnection, |
|
|
|
sqlServerOptionsAction: sqlOptions => |
|
|
|
{ |
|
|
|
sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name); |
|
|
|
//Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
|
|
|
|
sqlOptions.EnableRetryOnFailure(maxRetryCount: 5, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); |
|
|
|
}); |
|
|
|
|
|
|
|
options.ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)); |
|
|
|
}); |
|
|
|
|
|
|
|
services.Configure<Settings>(Configuration); |
|
|
|