DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Understanding Git
  • Unlock the Power of Software Heritage Archive
  • Deploying Prometheus and Grafana as Applications Using ArgoCD — Including Dashboards
  • Stop Using Spring Profiles Per Environment

Trending

  • New Free Tool From Contrast Security Makes API Security Testing Fast and Easy
  • Message Construction: Enhancing Enterprise Integration Patterns
  • Modular Software Architecture: Advantages and Disadvantages of Using Monolith, Microservices and Modular Monolith
  • Unleashing the Power of Microservices With Spring Cloud
  1. DZone
  2. Data Engineering
  3. Databases
  4. Explaining aggregates and repositories

Explaining aggregates and repositories

Oren Eini user avatar by
Oren Eini
·
Mar. 02, 12 · News
Like (0)
Save
Tweet
Share
3.84K Views

Join the DZone community and get the full member experience.

Join For Free

with regards to my recommendation to avoid the repository, stan asks :

you returned to explain why repository pattern is evil. just interesting to know what are you doing when you need in your model to access another aggregate. do you reference nh from your model? i prefer to leave my model pocoed and wrap db calls by repository pattern. sleeping good with it.

this is an interesting question. there are several ways to answer that. to start with, assuming that we are using ddd model (which the usage of a repository would imply), you don’t have references between aggregates.

but let us assume that we somehow need that, stan seems to suggest something like this proposed solution :

public class person 
{
    public static readonly datetime importantdate;
    public birthplace birthplace { get; set; } 

    public datetime birthdate 
    { 
        get; private set;
    } 

    public void correctbirthdate(irepository<birthplace> birthplaces, datetime date)
    {
        if (birthplace != null && date < importantdate && birthplace.isspecial) 
        { 
            birthplace = birthplaces.getfordate(date); 
        }
    }
}

here we have a business rule that states that this is required.

but do we actually need a repository here? what if we just said that whoever calls us need to provide us with a way to get the birth place by date?

public void correctbirthdate(
        func<datetime, birthplace> getbirthplacefordate, 
        datetime date)
{
    if (birthplace != null && date < importantdate && birthplace.isspecial) 
    { 
        birthplace = getbirthplacefordate(date); 
    }
}

this can be done with a simple delegate, no need to introduce a heavy weight abstraction. this is a local solution for a local problem. it keeps the database out from your entities and more importantly, it allows you to actually craft the appropriate response to this at the time of the call .

Repository (version control)

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Understanding Git
  • Unlock the Power of Software Heritage Archive
  • Deploying Prometheus and Grafana as Applications Using ArgoCD — Including Dashboards
  • Stop Using Spring Profiles Per Environment

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: