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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:44:30+00:00 2026-06-10T03:44:30+00:00

Two months ago I bought the book Professional ASP.NET Design Patterns by Scott Millet

  • 0

Two months ago I bought the book “Professional ASP.NET Design Patterns” by Scott Millet because I wanted to learn how to build a layered web application using design patterns. I used the case study from this book in my own application so everything is set up.

The problem I have is that I am not sure about my aggregate roots.

I have a user that can create collections. A user can add categories to a collection and keywords to the categories. It looks like this in my database:

- Users
    - PK: UserId

- Collections
    - PK: CollectionId
    - FK: UserId

- Categories
    - PK: CategoryId
    - FK: CollectionId

- Keywords
    - PK: KeywordId
    - FK: CategoryId

I don’t find it logical to make user the aggregate root of collection, but categories and keywords together form a collection. So I made user an aggregate root which has no children yet, and collections an aggregate root. A single collection can have multiple categories and categories can have multiple keywords. So when I want to add a category I do this:

public void CreateCategory(CreateCategoryRequest request)
    {
        Collection collection = _collectionRepository.FindCollection(request.IdentityToken, request.CollectionName);

        Category category = new Category { Collection = collection, CategoryName = request.CategoryName };

        ThrowExceptionIfCategoryIsInvalid(category);

        collection.AddCategory(category);

        _collectionRepository.Add(collection);
        _uow.Commit();
    }

Which works perfectly fine, but when I want to add a keyword I first need to get the collection and then get the category where I can add a keyword to and then commit the collection:

public void CreateKeyword(CreateKeywordRequest request)
    {
        Collection collection = _collectionRepository.FindCollection(request.IdentityToken, request.CollectionName);

        Category category = collection.Categories.Where(c => c.CategoryName == request.CategoryName).FirstOrDefault();

        Keyword keyword = new Keyword { Category = category, KeywordName = request.KeywordName, Description = request.KeywordDescription };

        category.AddKeyword(keyword);

        _collectionRepository.Add(collection);
        _uow.Commit();
    }

And this just don’t feel right (is it?) what made me believe that I should maybe make category the aggregate root of keyword. But that raises another question: is it still valid that I have a collection aggregate which creates a category aggregate like I did in my first code example? Example: collection.Add(category);

  • 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-06-10T03:44:32+00:00Added an answer on June 10, 2026 at 3:44 am

    An aggregate root can certainly contain nested children, however if those children are also aggregates that may be a warning that perhaps the aggregate is doing too much. In your case, I think Collection is an aggregate and Category is not, it is just an entity or even a value object belonging to the Collection aggregate and it happens to contain Keyword instances which are also value objects.

    I would change the implementation so that the CreateCategory service method looks more like this:

    public void CreateCategory(CreateCategoryRequest request)
    {
            var collection = _collectionRepository.Get(request.IdentityToken, request.CollectionName);
    
            collection.AddCategory(request.CategoryName);
    
            _uow.Commit();
    }
    

    The AddCategory method on the Collection is responsible for creating the Category instance as well as error checking. This makes sense because it is the aggregate root and it is responsible for managing the cluster of entities and value objects it contains. There is no call to the Add method on the repository because the ambient unit of work should commit the changes.

    The CreateKeyword method I would change to look more like:

    public void CreateKeyword(CreateKeywordRequest request)
    {
            var collection = _collectionRepository.Get(request.IdentityToken, request.CollectionName);
    
            collection.AddKeyword(request.CategoryName, request.KeywordName, request.KeywordDescription);
    
            _uow.Commit();
    }
    

    The AddKeyword method on Collection retrieves the appropriate Category and then adds a keyword to it, throwing exceptions if needed to enforce consistency and validity.

    As you can see, there is a pattern to these two methods – first an aggregate is retrieved by a key, then a method on the aggregate is invoked, and finally everything is committed. In this way, the aggregates have more control over their own state and you avoid having an anemic domain model as well as reducing the amount of code present in services.

    For an in depth treatment of aggregate design, take a look at Effective Aggregate Design by Vaughn Vernon.

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

Sidebar

Related Questions

Several months (maybe even a year or two) ago, I saw an asp .net
Ben Copsey has abandoned ASIHTTPRequest. It has been announced almost two months ago but
Lately I've been rethinking a database design I made a couple of months ago.
About two months ago, I upgraded a SilverStripe website from 2.3.5 to 2.4.6. Since
I started iPhone development two months ago, so I can't call myself expert ;-)
Few months ago, I developed two template pages on wordpress 3.1 and they were
I started using Git a few months ago and I wanted a GUI client
So two months ago I migrated our codebase in SVN into Git with the
I asked this question two months ago and got nary an answer. In fact
Edited to add more details: (originally asked nearly two months ago...still haven't found a

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.