-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from klauffer/main
- Loading branch information
Showing
10 changed files
with
266 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using AndcultureCode.CSharp.Core.Interfaces; | ||
using AndcultureCode.CSharp.Core.Interfaces.Conductors; | ||
using AndcultureCode.CSharp.Core.Models.Entities; | ||
|
||
namespace AndcultureCode.CSharp.Conductors | ||
{ | ||
public partial class RepositoryConductor<T> : Conductor, IRepositoryConductor<T> | ||
where T : Entity | ||
{ | ||
#region Properties | ||
|
||
/// <summary> | ||
/// Ability to set and get the underlying repository's command timeout | ||
/// </summary> | ||
public int? CommandTimeout | ||
{ | ||
get => _readConductor.CommandTimeout; | ||
set | ||
{ | ||
_createConductor.CommandTimeout = value; | ||
_deleteConductor.CommandTimeout = value; | ||
_readConductor.CommandTimeout = value; | ||
_updateConductor.CommandTimeout = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Conductor property to create an entity or entities | ||
/// </summary> | ||
protected readonly IRepositoryCreateConductor<T> _createConductor; | ||
|
||
/// <summary> | ||
/// Conductor property to get an entity or entities | ||
/// </summary> | ||
protected readonly IRepositoryReadConductor<T> _readConductor; | ||
|
||
/// <summary> | ||
/// Conductor property to update an entity or entities | ||
/// </summary> | ||
protected readonly IRepositoryUpdateConductor<T> _updateConductor; | ||
|
||
/// <summary> | ||
/// Conductor property to delete an entity or entities | ||
/// </summary> | ||
protected readonly IRepositoryDeleteConductor<T> _deleteConductor; | ||
|
||
#endregion Properties | ||
|
||
#region Constructor | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="createConductor">The conductor instance that should be used to perform create operations</param> | ||
/// <param name="readConductor">The conductor instance that should be used to perform read operations</param> | ||
/// <param name="updateConductor">The conductor instance that should be used to perform update operations</param> | ||
/// <param name="deleteConductor">The conductor instance that should be used to perform delete operations</param> | ||
public RepositoryConductor( | ||
IRepositoryCreateConductor<T> createConductor, | ||
IRepositoryReadConductor<T> readConductor, | ||
IRepositoryUpdateConductor<T> updateConductor, | ||
IRepositoryDeleteConductor<T> deleteConductor) | ||
{ | ||
_createConductor = createConductor; | ||
_readConductor = readConductor; | ||
_updateConductor = updateConductor; | ||
_deleteConductor = deleteConductor; | ||
} | ||
|
||
#endregion Constructor | ||
|
||
|
||
public Task<IResult<List<T>>> BulkCreateAsync(IEnumerable<T> items, long? createdById = null) => | ||
_createConductor.BulkCreateAsync(items, createdById); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AndcultureCode.CSharp.Core.Interfaces; | ||
using AndcultureCode.CSharp.Core.Interfaces.Conductors; | ||
using AndcultureCode.CSharp.Core.Interfaces.Data; | ||
using AndcultureCode.CSharp.Core.Interfaces.Entity; | ||
|
||
namespace AndcultureCode.CSharp.Conductors | ||
{ | ||
public partial class RepositoryCreateConductor<T> : Conductor, IRepositoryCreateConductor<T> | ||
where T : class, IEntity | ||
{ | ||
/// <summary> | ||
/// Ability to set and get the underlying DbContext's command timeout | ||
/// </summary> | ||
public int? CommandTimeout | ||
{ | ||
get => _repository.CommandTimeout; | ||
set => _repository.CommandTimeout = value; | ||
} | ||
|
||
readonly IRepository<T> _repository; | ||
|
||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="repository"></param> | ||
public RepositoryCreateConductor( | ||
IRepository<T> repository | ||
) | ||
{ | ||
_repository = repository; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public virtual Task<IResult<List<T>>> BulkCreateAsync(IEnumerable<T> items, long? createdById = null) | ||
{ | ||
if(items == null) throw new ArgumentNullException(nameof(items)); | ||
if(!items.Any()) throw new ArgumentException("An empty collection was provided", nameof(items)); | ||
return _repository.BulkCreateAsync(items, createdById); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Core/Interfaces/Conductors/IRepositoryCreateConductorAsync.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using AndcultureCode.CSharp.Core.Interfaces.Entity; | ||
|
||
namespace AndcultureCode.CSharp.Core.Interfaces.Conductors | ||
{ | ||
public partial interface IRepositoryCreateConductor<T> | ||
where T : class, IEntity | ||
{ | ||
/// <summary> | ||
/// Ability to asynchronously create entities using a list in a single bulk operation. | ||
/// </summary> | ||
/// <param name="items">List of items to create</param> | ||
/// <param name="createdById">Id of user creating the items</param> | ||
/// <returns>A collection of the created items</returns> | ||
Task<IResult<List<T>>> BulkCreateAsync(IEnumerable<T> items, long? createdById = null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using AndcultureCode.CSharp.Core.Interfaces.Entity; | ||
|
||
namespace AndcultureCode.CSharp.Core.Interfaces.Data | ||
{ | ||
public partial interface IRepository<T> | ||
where T : class, IEntity | ||
{ | ||
/// <summary> | ||
/// Perform a DbContext.BulkInsert on an enumeration of T within a single transaction | ||
/// </summary> | ||
/// <param name="items"></param> | ||
/// <param name="createdById"></param> | ||
/// <returns></returns> | ||
Task<IResult<List<T>>> BulkCreateAsync(IEnumerable<T> items, long? createdById = null); | ||
|
||
} | ||
} |
Oops, something went wrong.