using System; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using xCommons.Extensions; using xDataService.Constants; using xDataService.Db; using xExceptions.Constants; namespace xDataService.Helpers { public static class XDataServiceHelper { /// /// Register DbContext ... /// /// /// /// /// /// /// public static void AddXDbContext( IServiceCollection source, XDbProviders provider, string connectionString, ServiceLifetime lifetime = ServiceLifetime.Scoped, Action optionsBuilder = null ) where TContext : XDbContext { // if (provider == XDbProviders.None) { // // Log("Invalid Db Provider ..."); XException.InvalidArgs.Throw(); } // switch (provider) { // // MySQL ... case XDbProviders.MySQL: // source.AddDbContext(cfg => { cfg.UseMySQL(connectionString, optionsBuilder); }, lifetime); break; // // SQLite ... case XDbProviders.SQLite: // source.AddDbContext(cfg => { cfg.UseSqlite(connectionString, optionsBuilder); }, lifetime); break; // // SQLServer ... case XDbProviders.SQLServer: // source.AddDbContext(cfg => { cfg.UseSqlServer(connectionString, optionsBuilder); }, lifetime); break; // case XDbProviders.MongoDB: // There is notRequired to Register DBConext forMongo DB ... break; } } } }