Skip to content

Commit

Permalink
Merge pull request #47 from klauffer/main
Browse files Browse the repository at this point in the history
Issue #17 and #34 initial steps
  • Loading branch information
klauffer authored Mar 25, 2022
2 parents 3708c24 + a4c6287 commit 18464d6
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 102 deletions.
68 changes: 4 additions & 64 deletions src/Conductors/RepositoryConductor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using AndcultureCode.CSharp.Core;
using AndcultureCode.CSharp.Core.Extensions;
using AndcultureCode.CSharp.Core.Interfaces;
Expand All @@ -14,71 +15,9 @@ namespace AndcultureCode.CSharp.Conductors
/// Provides CRUD operations on a given repository
/// </summary>
/// <typeparam name="T"></typeparam>
public class RepositoryConductor<T> : Conductor, IRepositoryConductor<T>
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

#region Public Methods

#region Create
Expand All @@ -88,7 +27,8 @@ public RepositoryConductor(
/// </summary>
/// <param name="items">List of items to create</param>
/// <param name="createdById">Id of user creating the items</param>
/// <returns></returns>
/// <returns>A collection of the created items</returns>
[Obsolete("This method is deprecated in favor of its async counter part", false)]
public virtual IResult<List<T>> BulkCreate(IEnumerable<T> items, long? createdById = default(long?)) => _createConductor.BulkCreate(items, createdById);

/// <summary>
Expand Down
78 changes: 78 additions & 0 deletions src/Conductors/RepositoryConductorAsync.cs
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);
}
}
39 changes: 3 additions & 36 deletions src/Conductors/RepositoryCreateConductor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AndcultureCode.CSharp.Core.Interfaces;
using AndcultureCode.CSharp.Core.Interfaces.Conductors;
using AndcultureCode.CSharp.Core.Interfaces.Data;
Expand All @@ -11,47 +12,13 @@ namespace AndcultureCode.CSharp.Conductors
/// Ability to create an entity or multiple entities
/// </summary>
/// <typeparam name="T"></typeparam>
public class RepositoryCreateConductor<T> : Conductor, IRepositoryCreateConductor<T>
public partial class RepositoryCreateConductor<T> : Conductor, IRepositoryCreateConductor<T>
where T : class, IEntity
{
#region Properties

/// <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;

#endregion

#region Constructor

/// <summary>
/// Constructor
/// </summary>
/// <param name="repository"></param>
public RepositoryCreateConductor(
IRepository<T> repository
)
{
_repository = repository;
}

#endregion

#region IRepositoryCreateConductor

/// <summary>
/// Ability to 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></returns>
/// <inheritdoc />
public virtual IResult<List<T>> BulkCreate(IEnumerable<T> items, long? createdById = default(long?))
{
return _repository.BulkCreate(items, createdById);
Expand Down
46 changes: 46 additions & 0 deletions src/Conductors/RepositoryCreateConductorAsync.cs
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);
}
}
}
9 changes: 8 additions & 1 deletion src/Core/Interfaces/Conductors/IRepositoryCreateConductor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace AndcultureCode.CSharp.Core.Interfaces.Conductors
{
public interface IRepositoryCreateConductor<T>
public partial interface IRepositoryCreateConductor<T>
where T : class, IEntity
{
#region Properties
Expand All @@ -19,6 +19,13 @@ public interface IRepositoryCreateConductor<T>

#region Methods

/// <summary>
/// Ability to 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></returns>
[Obsolete("This method is deprecated in favor of its async counter part", false)]
IResult<List<T>> BulkCreate(IEnumerable<T> items, long? createdById = null);

/// <summary>
Expand Down
20 changes: 20 additions & 0 deletions src/Core/Interfaces/Conductors/IRepositoryCreateConductorAsync.cs
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);
}
}
2 changes: 1 addition & 1 deletion src/Core/Interfaces/Data/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace AndcultureCode.CSharp.Core.Interfaces.Data
///
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IRepository<T>
public partial interface IRepository<T>
where T : class, IEntity
{
#region Properties
Expand Down
19 changes: 19 additions & 0 deletions src/Core/Interfaces/Data/IRepositoryAsync.cs
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);

}
}
Loading

0 comments on commit 18464d6

Please sign in to comment.