Question

I'm developing an application with Domain Drive Design approach. in a special case I have to retrieve the list of value objects of an aggregate and present them. to do that I've created a read only repository like this:

 public interface IBlogTagReadOnlyRepository : IReadOnlyRepository<BlogTag, string>
    {
        IEnumerable<BlogTag> GetAllBlogTagsQuery(string tagName);
    }

BlogTag is a value object in Blog aggregate, now it works fine but when I think about this way of handling and the future of the project, my concerns grow! it's not a good idea to create a separate read only repository for every value object included in those cases, is it? anybody knows a better solution?

Was it helpful?

Solution 2

I think you just need a query service as this method serves the user interface, it's just for presentation (reporting), do something like..

public IEnumerable<BlogTagViewModel> GetDistinctListOfBlogTagsForPublishedPosts()
{
    var tags = new List<BlogTagViewModel>();

    // Go to database and run query
    // transform to collection of BlogTagViewModel

    return tags;
}

This code would be at the application layer level not the domain layer.

And notice the language I use in the method name, it makes it a bit more explicit and tells people using the query exactly what the method does (if this is your intent - I am guessing a little, but hopefully you get what I mean).

Cheers Scott

OTHER TIPS

You should not keep value objects in their own repository since only aggregate roots belong there. Instead you should review your domain model carefully.

If you need to keep track of value objects spanning multiple aggregates, then maybe they belong to another aggregate (e.g. a tag cloud) that could even serve as sort of a factory for the tags.

This doesn't mean you don't need a BlogTag value object in your Blog aggregate. A value object in one aggregate could be an entity in another or even an aggregate root by itself.

Maybe you should take a look at this question. It addresses a similar problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top