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 3361982
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:13:06+00:00 2026-05-18T03:13:06+00:00

Or should I always get my entities via service methods? Thanks

  • 0

Or should I always get my entities via service methods?

Thanks

  • 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-18T03:13:06+00:00Added an answer on May 18, 2026 at 3:13 am

    Most of the time I try to separate my layers as much as possible. Usually I’ll have my services act as facades to the business logic. Within business logic I use a DI Container, like Unity, to resolve my repositories…

    Example:

    IUnityContainer container = IoCManager.Container;
    using (var repository = container.Resolve<IRepository<Token>>())
    {
        return repository.Eagerly(f => f.Fetch<TokenSetting>(t => t.Settings))
                         .Where(t => t.Value == tokenGuid && t.Expired == null)
                         .FirstOrDefault();
    }
    

    My business logic contains no dependencies now on my infrastructure layer (repositories). For a great Repository implementation take a look at NCommon. Ritesh Rao wrote some great examples of pattern usage for DDD.

    Whether it’s wrong to reference your repositories is subjective. I think DDD purists will tell you it most likely is. “How much SoC are you trying to achieve” is the real question. It’s usually best to strive for high cohesion via loose coupling, but sometimes that can be overkill.

    Hope this helps.


    [EDITED]

    Repositories can exist within the domain. Really they sit in between your business logic / model and your infrastructure model. You are correct to depend on the interface not implementation.

    Look at Martin Fowler’s – Separated Interface Pattern. In my above example I depend on the interface. The DI container resolves the actual implementation of my concrete repository class. Here is a sample DDD diagram I’ve been refining as I learn.
    alt text

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

Sidebar

Related Questions

I always thought you should never set/get a member variable directly. E.g. $x =
should always the version field be checked when updating a domain class object ?
True or not: We should always use proper capitalization and never put whole sentences
In the below thisIsAlwaysTrue should always be true. DateTime d = DateTime.Now; bool thisIsAlwaysTrue
We generate web pages that should always be printed in landscape mode. Web browser
What are the security topics that you should always include when writing a proposal
I have previously been told that I should always use Randomize() before I use
It seems to me that one should always properly dispose resources when calling Directory
IMHO Radio buttons should retire. The ComboBox (Drop-Down list mode) should always be preferred.
I had a developer tell me recently that you should ALWAYS do database calls

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.