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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:29:04+00:00 2026-05-20T05:29:04+00:00

Or I don’t understand this at all. I have started my ASP.NET MVC application

  • 0

Or I don’t understand this at all.

I have started my ASP.NET MVC application using the Controller –> ViewModel –> Service –> Repository pattern.

Does every type of object (Customer, Product, Category, Invoice, etc..) need to have it’s own repository and service? If so, how do you bring common items together?

I mean there are a lot of the times when a few of these things will be displayed on the same page. So I am not getting this I don’t think.

So I was thinking I need a ShopController, which has a ShopViewModel, which could have categories, sub categoires, products, etc. But the problem, for me, is that it just does not seem to mesh well.

Maybe ASP.NET WebForms were for people like me 🙂

Edit

So would an aggregate consist of say:

Category, SubCategory, Product, ChildProduct, ProductReview with the Product being the aggregate root?

Then in the ViewModels, you would access the Product to get at it’s child products, reviews, etc.

I am using entity framework 4, so how would you implement lazy loading using the repository/service pattern?

  • 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-20T05:29:05+00:00Added an answer on May 20, 2026 at 5:29 am

    Does every type of object (Customer,
    Product, Category, Invoice, etc..)
    need to have it’s own repository

    You should have a repository per aggregate root in your domain. See this question for more information on what is an aggregate root.

    In the example you give I could see a CustomerReposiotry which would handle retrieve all pertinent customer data(Customer has orders a order has a customer). A ProductRepository that handles retrieving product information.

    and service? If so, how do you bring
    common items together?

    A service layer is nice but only if there is added value in adding this layer. If your service simply passes straight into the repository it might not be needed. However if you need to perform certain business logic on a Product a ProductService might make sense.

    This might not make sense

    public void UpdateProduct(Product product)
    {
      _repo.Update(product);
    }
    

    But if you have logic this layer makes sense to encapsulate your business rules for products.

    public void UpdateProduct(Product productToUpdate)
    {
      //Perform some sort of business on the productToUpdate, raise domain events, ....
      _repo.Update(productToUpdate);
    }
    

    So I was thinking I need a
    ShopController, which has a
    ShopViewModel, which could have
    categories, sub categoires, products,
    etc. But the problem, for me, is that
    it just does not seem to mesh well.

    If the domain is flushed out the view model ends up making sense

    public ActionResult Index()
    {
      ShopViewModel shopViewModel = new ShopViewModel();
      shopViewModel.Products = _productRepo.GetAll();
      //other stuff on the view model.
      return(shopViewModel);
    }
    

    Update

    What happens when you also need to
    provide data unobtainable from an
    aggregate root? For example, say I
    have a create Customer view and in
    that view, I also need to provide the
    user with a collection of Companies to
    choose from to associate a new
    customer with. Does the collection of
    Companies come from CustomerRepository
    or would you also need a
    CompanyRepository?

    If a Company can live by itself (e.g. you edit, update, delete a company) I would suggest a Company is also an aggregate root for your domain (A Customer has a company and a company has a list of Customers). However if a Company is only obtainable via a Customer, I would treat a company as a ValueType/Value Object. If that is the case I would create a method on the customer repository to retrive all CompanyNames.

    _repo.GetAllCompanyNames();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't understand where the extra bits are coming from in this article about
I don’t think I’ve grokked currying yet. I understand what it does, and how
I don't expect a straightforward silver bullet answer to this, but what are the
I don't know if anyone has seen this issue before but I'm just stumped.
I don't currently use ajax.net though I would be open to it if it
Don't you hate it when you have class Foobar { public: Something& getSomething(int index)
I have found this example on StackOverflow: var people = new List<Person> { new
I don't know when to add to a dataset a tableadapter or a query
I don't edit CSS very often, and almost every time I need to go
I don't want PHP errors to display /html, but I want them to display

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.