Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6817233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:01:32+00:00 2026-05-26T21:01:32+00:00

I’ve been trawling stackoverflow and the internet in general all day about the IRepository

  • 0

I’ve been trawling stackoverflow and the internet in general all day about the IRepository pattern trying to better understand it before I try and use it in anger.

From what I’ve read (and please do correct me if I’m mistaken) a repoistory encapsulates access to its aggregate root and child objects exposing a common interface that can then be injected or mocked.

So in the instance where you have your aggregate root object:

class Employee {
    string FirstName;
    string LastName;
    IEnumerable<Address> Addresses;
    IEnumerable<PhoneNumber> PhoneNumbers;
}

Then its child objects:

class Address {
    string BuildingName;
    ...etc
}

class PhoneNumber {
    string PhoneNo;
    ...etc
}

So the repository would look something like:

class EmployeeRepository : IRepository<Employee> {
    Employee Get(id) {
    ...does stuff, builds full Employee object including Addresses/Phone No's and returns
    }
}

But say I dont want to get the whole Employee, say I just want the flat Employee record with FirstName LastName and be able to lazy load in the rest in later. How should this be accomplished? Would it be permissible to have something like:

class EmployeeRepository : IRepository<Employee> {
    Employee Get(id) {
    ...does stuff and builds flat Employee object without Addresses and Phone Numbers
    }

    Employee GetAddresses (Employee emp) {
    ...
    }

    Employee GetPhoneNumbers (Employee emp) {
    ...
    }
}

Is this ok or would I be breaking some sacrosanct DDD rule and burn in developer hell? How is lazy loading supposed to fit this model, again tried searching but all I’ve found is “let NHibernate/Entity Framework/ORM do it for you”.

Thanks in advance.

D.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:01:32+00:00Added an answer on May 26, 2026 at 9:01 pm

    true lazy loading would mean that you have references to proxy objects in the properties of your aggregate root (and anywhere else in the object graph you wind up loading lazily) that would be smart enough to load the real entity and replace the proxy with it when properties are invoked that require it. using something like castle’s dynamic proxy or linfu’s dynamic proxy are the best way to do this because dynamic proxies are complex beasts that have been well implemented by those guys.

    doing what you have suggested requires that your consuming code be aware of what has and hasn’t been loaded and puts the burden on the user to know about the lazy loading and think about it in the client code. with a dynamic proxy, you don’t have to think about it.

    really, the best answer, though, is the one you have already found. this is a problem that has been solved by ORMs. use NHibernate and worry about your domain rather than implementing something that is already implemented and well tested and used by tons of other projects. it’s a problem with a lot of nuances and you are better off using what is already out there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am reading a book about Javascript and jQuery and using one of the
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.