public async Task <TEntity> Add(TEntity entity, CancellationToken cancellationToken = default)
    {
        if (entity == null)
        {
            throw new ArgumentNullException(nameof(entity));
        }

        var entry = await dbContext.AddAsync(entity, cancellationToken);

        aggregateEventsPublisher.TryEnqueueEventsFrom(entity, out _);

        return(entry.Entity);
    }
Esempio n. 2
0
        public async Task <TEntity> Add(TEntity entity, CancellationToken cancellationToken = default)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var sql = dapperSqlGenerator?.Add(entity);

            if (!sql.IsNullOrEmpty())
            {
                await dbConnection.ExecuteAsync(sql, entity);
            }
            else
            {
                await dbConnection.InsertAsync(entity);
            }

            aggregateEventsPublisher.TryEnqueueEventsFrom(entity, out _);

            return(entity);
        }