public static StepFunctionsBuilder AddSqlWorkers(this StepFunctionsBuilder builder, IEnumerable <DatabaseConfig> databases) { builder.ServiceCollection.AddTransient <SqlServerBaseDatabase>(); builder.ServiceCollection.AddTransient <OracleDatabase>(); builder.ServiceCollection.AddTransient <MySqlDatabase>(); builder.ServiceCollection.AddTransient <PostgreSqlBaseDatabase>(); if (databases != null) { foreach (var database in databases) { builder.ServiceCollection.AddSingleton <BaseDatabase>(x => { BaseDatabase db = (BaseDatabase)x.GetService(Type.GetType(database.Type)); db.Config = database; return(db); }); } } builder.AddWorker <SqlQueryWorker>(); builder.AddWorker <SqlBulkInsertWorker>(); builder.AddWorker <SqlExportToCsvWorker>(); return(builder); }
public static StepFunctionsBuilder AddSqlWorkers(this StepFunctionsBuilder builder, IEnumerable <DatabaseConfig> databases) { if (databases != null) { foreach (var database in databases) { switch (database.Type) { case SqlDatabaseType.SqlServer: builder.ServiceCollection.AddSingleton <BaseDatabase>(x => new SqlServerBaseDatabase(database)); break; case SqlDatabaseType.PostgreSql: builder.ServiceCollection.AddSingleton <BaseDatabase>(x => new PostgreSqlBaseDatabase(database)); break; case SqlDatabaseType.MariaDb: case SqlDatabaseType.MySql: builder.ServiceCollection.AddSingleton <BaseDatabase>(x => new MySqlDatabase(database)); break; default: throw new ArgumentOutOfRangeException(); } } } builder.AddWorker <SqlQueryWorker>(); builder.AddWorker <SqlBulkInsertWorker>(); return(builder); }