public static IServiceCollection AddEFCore <TDbContext>(this IServiceCollection services, string connectionstring, IHostEnvironment hostEnvironment) where TDbContext : DbContext { switch (DbConnectionFactory.DiscoverDatabaseType(connectionstring)) { case DatabaseType.SQL: services.AddDbContext <TDbContext>(options => options.UseSqlServer(connectionstring).SetupSensitiveLogging(hostEnvironment)); break; case DatabaseType.ORACLE: services.AddDbContext <TDbContext>(options => options.UseOracle(connectionstring).SetupSensitiveLogging(hostEnvironment)); break; default: throw new NotSupportedException(); } return(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddEFCore <PokemonDbContext>(Configuration.GetConnectionString("Pokemons"), hostEnvironment); switch (DbConnectionFactory.DiscoverDatabaseType(Configuration.GetConnectionString("Pokemons"))) { case DatabaseType.SQL: services.AddScoped <IPokemonRepository, PokemonsSql>(); break; case DatabaseType.ORACLE: services.AddScoped <IPokemonRepository, PokemonsOracle>(); break; default: throw new NotSupportedException(); } services.AddScoped <IPokemonService, PokemonService>(); services.AddControllers(); }