Eiffel
  • Overview
    • About
  • Features
    • Cross cutting concerns
      • API response consistency
      • Global exception handling
      • Idempotency
      • Audit logging
    • Caching
      • Configuration
        • In-Memory
        • Redis
      • Usage
      • API
        • CacheSource
        • InMemoryCacheOptions
        • RedisCacheOptions
        • ICacheService
        • ICacheServiceFactory
    • Localization
    • Job Processing
    • Multi-Tenancy
    • Metrics & monitoring
    • Transactional outbox
      • PostgreSQL
      • MongoDB (cluster only)
    • Messaging
      • Kafka
      • Rabbit MQ
      • Azure Service Bus
    • Awaitable socket client
    • Graceful shutdown
  • Fundamentals
    • Persistence
    • Modelling
  • Principles
    • Domain-Driven Design
      • Aggregates
      • Entities
      • Value Objects
      • Domain Events
      • Factories
      • Domain Services
      • Business Identifiers
      • Shared Kernel
    • Onion Architecture
      • Application Layer
      • Domain Layer
      • Infrastructure Layer
      • Anti-Corruption Layer
    • Modular Monolith Architecture
      • Modules
      • Shared Infrastructure
    • Microservice Architecture
      • API Gateway
      • View Model Composition
      • Contracts
  • Business Aligment
    • Domain Storytelling
    • User stories
  • Implementation
    • Modular Monolith
    • Microservices
  • Testing
    • Unit Testing
    • Integration Testing
    • Contract Testing
  • Cloud Infrastructure
    • CI/CD Pipelines
    • Docker
    • Kubernates
    • Infrastructure as Code
Powered by GitBook
On this page
  1. Fundamentals

Persistence

Repository base class and other requirements.

Motivation

A repository represents all objects of a certain type as a conceptual set (usually emulated). It acts like a collection, except with more elaborate querying capability. [...] For each type of object that needs global access, create an object that can provide the illusion of an in-memory collection of all objects of that type. Eric Evans - Domain Driven Design

Most repository patterns contain many query methods, and they are often nearly identical to the DbContext class. Unlike the norm, the Eiffel framework follows a collection-oriented repository approach."

Each repository should expose a single aggregate, and the maintenance of the entities or value objects should be handled by the owner aggregate.

/// <summary>
/// IRepository interface
/// </summary>
/// <typeparam name="TAggregate">The type of aggregate</typeparam>
/// <typeparam name="TIdentity">The tpye of aggregate identity</typeparam>
/// <typeparam name="TKey">The type of database primary key</typeparam>
public interface IRepository<TAggregate, TIdentity, TKey>
    where TKey : struct, IEquatable<TKey>
    where TIdentity : class
    where TAggregate : Aggregate<TIdentity, TKey>
{
    /// <summary>
    /// Gets record from database
    /// </summary>
    /// <param name="identity">Aggregate</param>
    /// <param name="cancellationToken">Cancellation token</param>
    Task<TAggregate> GetAsync(TIdentity identity, CancellationToken cancellationToken = default);

    /// <summary>
    /// Adds record to database
    /// </summary>
    /// <param name="aggregate">Aggregate identifier</param>
    /// <param name="cancellationToken">Cancellation token</param>
    /// <returns>Record from database</returns>
    Task AddAsync(TAggregate aggregate, CancellationToken cancellationToken = default);


    /// <summary>
    /// Commit changes to database
    /// </summary>
    /// <param name="aggregate">Aggregate</param>
    /// <param name="cancellationToken">Cancellation token</param>
    Task SaveChangesAsync(TAggregate aggregate, CancellationToken cancellationToken = default);
}
PreviousGraceful shutdownNextModelling

Last updated 1 year ago