Developer 02 0c529b199b Bump version numbers and enhance repository interfaces
- Incremented version numbers in project files for updates.
- Marked `ICRUDRepository` as obsolete; use `IRepository` instead.
- Improved parameter names and signatures in `IRepository`.
- Changed access modifiers in `DbRepository` for broader access.
- Updated `CreateAsync` and `UpdateAsync` methods for async operations.
- Implemented `ReadAsync` and `DeleteAsync` methods in `DbRepository`.
- Minor whitespace change in `.csproj` files.
- Retained package description in `DigitalData.Core.Infrastructure.csproj`.
2025-04-17 12:53:40 +02:00

62 lines
2.7 KiB
C#

namespace DigitalData.Core.Abstractions.Infrastructure
{
/// <summary>
/// Defines the contract for CRUD operations on a repository for entities of type TEntity.
/// </summary>
/// <typeparam name="TEntity">The type of the entity this repository works with.</typeparam>
/// <typeparam name="TId">The type of the identifier for the entity.</typeparam>
public interface ICRUDRepository<TEntity, TId> where TEntity : class, IUnique<TId>
{
/// <summary>
/// Adds a new entity to the repository.
/// </summary>
/// <param name="entity">The entity to add.</param>
/// <returns>The added entity, or null if the entity cannot be added.</returns>
Task<TEntity?> CreateAsync(TEntity entity);
/// <summary>
/// Retrieves an entity by its identifier from the repository.
/// </summary>
/// <param name="id">The identifier of the entity to retrieve.</param>
/// <returns>The entity found, or null if no entity is found.</returns>
Task<TEntity?> ReadByIdAsync(TId id);
/// <summary>
/// Retrieves all entities from the repository.
/// </summary>
/// <returns>A collection of all entities.</returns>
Task<IEnumerable<TEntity>> ReadAllAsync();
/// <summary>
/// Updates an existing entity in the repository.
/// </summary>
/// <param name="entity">The entity to update.</param>
/// <returns>The updated entity.</returns>
Task<bool> UpdateAsync(TEntity entity);
/// <summary>
/// Deletes an entity from the repository.
/// </summary>
/// <param name="entity">The entity to delete.</param>
/// <returns>If entity is deleted, return true othwerwise return false.</returns>
Task<bool> DeleteAsync(TEntity entity);
/// <summary>
/// Asynchronously counts all entities in the repository.
/// </summary>
/// <returns>The total number of entities in the repository.</returns>
Task<int> CountAsync();
/// <summary>
/// Asynchronously counts the number of entities in the repository that match a specific identifier.
/// </summary>
/// <param name="id">The identifier of the entities to count.</param>
/// <returns>The number of entities with the specified identifier.</returns>
/// <remarks>
/// This method provides a count of entities in the database that match the given identifier.
/// If there are multiple entities with the same identifier, they will all be counted.
/// The default implementation assumes that the identifier is unique for each entity.
/// </remarks>
Task<int> CountAsync(TId id);
}
}