Skip to content

Instantly share code, notes, and snippets.

@glen-84
Created February 2, 2024 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glen-84/f9629976e8fac78c514c83a154f46c7b to your computer and use it in GitHub Desktop.
Save glen-84/f9629976e8fac78c514c83a154f46c7b to your computer and use it in GitHub Desktop.
Generic repository interface
public interface IRepository<TAggregateRoot> where TAggregateRoot : IAggregateRoot
{
public void Add(params TAggregateRoot[] entities);
public void Remove(params TAggregateRoot[] entities);
public Task<TAggregateRoot?> SingleOrDefaultAsync(
ISpecification<TAggregateRoot> specification,
CancellationToken cancellationToken = default);
public Task<TResult?> SingleOrDefaultAsync<TResult>(
ISpecification<TAggregateRoot, TResult> specification,
CancellationToken cancellationToken = default);
public Task<TAggregateRoot?> SingleOrDefaultByIdAsync<TId>(
TId entityId,
CancellationToken cancellationToken = default)
where TId : IId;
public Task<IList<TAggregateRoot>> ListAsync(
ISpecification<TAggregateRoot> specification,
CancellationToken cancellationToken = default);
public Task<IList<TResult>> ListAsync<TResult>(
ISpecification<TAggregateRoot, TResult> specification,
CancellationToken cancellationToken = default);
public Task<bool> IsUniqueAsync(ISpecification<TAggregateRoot> specification, IId? existingId);
public Task<int> DeleteAsync(
ISpecification<TAggregateRoot> specification,
CancellationToken cancellationToken = default);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment