/// <summary>
        /// Registers and configure bulk service
        /// </summary>
        /// <param name="services"></param>
        /// <param name="setupAction">Bulk Service configuration such as mapping</param>
        /// <returns></returns>
        public static IServiceCollection AddPostgreSqlBulkService(this IServiceCollection services, Action <BulkServiceOptions> setupAction)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var options = new BulkServiceOptions();

            setupAction(options);

            services.AddSingleton <IBulkServiceOptions>(options);
            services.AddTransient <IInsertSqlCommandBuilder, InsertSqlCommandBuilder>();
            services.AddTransient <IUpdateSqlCommandBuilder, UpdateSqlCommandBuilder>();
            services.AddTransient <IDeleteSqlCommandBuilder, DeleteSqlCommandMediator>();
            services.AddTransient <SimpleDeleteSqlCommandBuilder>();
            services.AddTransient <WhereInDeleteSqlCommandBuilder>();
            services.AddTransient <WhereOrDeleteSqlCommandBuilder>();
            services.AddTransient <IUpsertSqlCommandBuilder, UpsertSqlCommandBuilder>();

            services.AddTransient <IPostgreSqlBulkService>(
                sp => new NpgsqlCommandsBulkService(
                    options,
                    sp.GetRequiredService <ILoggerFactory>(),
                    sp.GetRequiredService <IInsertSqlCommandBuilder>(),
                    sp.GetRequiredService <IUpdateSqlCommandBuilder>(),
                    sp.GetRequiredService <IDeleteSqlCommandBuilder>(),
                    sp.GetRequiredService <IUpsertSqlCommandBuilder>()));

            return(services);
        }
Exemplo n.º 2
0
 public NpgsqlCommandsBulkService(
     BulkServiceOptions options,
     ILoggerFactory loggerFactory,
     IInsertSqlCommandBuilder insertCommandBuilder,
     IUpdateSqlCommandBuilder updateCommandBuilder,
     IDeleteSqlCommandBuilder deleteCommandBuilder,
     IUpsertSqlCommandBuilder upsertCommandBuilder)
 {
     _options = options;
     _insertCommandBuilder = insertCommandBuilder;
     _updateCommandBuilder = updateCommandBuilder;
     _deleteCommandBuilder = deleteCommandBuilder;
     _upsertCommandBuilder = upsertCommandBuilder;
     _logger = loggerFactory.CreateLogger <NpgsqlCommandsBulkService>();
 }