using System; using BlueWest.WebApi.EF; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace BlueWest.WebApi { /// /// Startup Extensions /// public static class StartupExtensions { /// /// Get MYSQL Connection String /// /// /// /// private static DbContextOptionsBuilder GetMySqlSettings( this DbContextOptionsBuilder optionsBuilder, IConfiguration configuration, IWebHostEnvironment environment) { var optionsBuilderRef = optionsBuilder.UseMySql(configuration.GetConnectionString("LocalMySQL"), new MySqlServerVersion(new Version(8, 0, 11))); // The following three options help with debugging, but should // be changed or removed for production. if (environment.IsDevelopment()) { optionsBuilderRef .LogTo(Console.WriteLine, LogLevel.Information) .EnableSensitiveDataLogging() .EnableDetailedErrors(); } return optionsBuilderRef; } /// /// Setup database Contexts /// /// /// /// /// public static IServiceCollection PrepareDatabasePool(this IServiceCollection serviceCollection, IConfiguration configuration, IWebHostEnvironment environment) { return serviceCollection .AddDbContextPool(options => options.GetMySqlSettings(configuration, environment)) .AddDbContextPool(options => options.GetMySqlSettings(configuration, environment)) .AddDbContextPool(options => options.GetMySqlSettings(configuration, environment)) .AddDbContextPool(options => options.GetMySqlSettings(configuration, environment)); } } }