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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:03:38+00:00 2026-05-15T10:03:38+00:00

We have a data provider class that returns repositories for each aggregate in our

  • 0

We have a data provider class that returns repositories for each aggregate in our database.

Let’s consider following scenario:

public class DataProvider {
    public IBookRepository Books { get { retun new BookRepository(); } }
    public IAuthorRepository Authors { get { retun new AuthorRepository(); } }
}

As you can see, we return a new Instance of the given object every time we call the Member: DataProvider.Books.DoBANANAS();

vs.

public class DataProvider {
    public IBookRepository Books { get; }
    public IAuthorRepository Authors { get; }

    public DataProvider()
    {
        Books = new BookRepository();
        Authors = new AuthorRepository();
    }
}

Will the call to `DataProvider.Books.BANANAS(); be less CPU / Memory heavy now?

As I just got around implementhing both version and they suprisingly worked!

But my experience tells me that Version 1 Sucks. Yet I’ve got more than enough time to fully optimize and implement the final product. (That’s one of the benefits of working in a research group)

  • 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-15T10:03:39+00:00Added an answer on May 15, 2026 at 10:03 am

    The implementations shown are different in how they construct and manage objects. In the first example, a new repository is created every time the property is called on the DataProvider. If the repository holds any state (eg. a cache of fetched objects), you will get very different behaviour than with the second example, because this state will be reset to its default each time.

    From the fact that you said both version work, I would hazard a guess that the repository objects do not hold state and are just proxies to the database calls. In this case, it probably will not have much difference.

    However, the performance and the memory profile of the two approaches are very different. Whilst premature optimisation is a bad thing and often a waste of time, I would not class this as such because making a new repository on each property call could clearly be a performance problem later, or worse still introduce hard to track down bugs if you introduce state into the repositories. Creating less objects will ultimately put less of a strain on the garbage collector, but unless you are creating millions of objects, it will be a negligible difference.

    In summary, the second example is the better one going forward, and I see no real problem considering that now.

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

Sidebar

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.