CQRS - Should a Command try to create a "complex" master-detail entity?

Posted by Simon Crabtree on Stack Overflow See other posts from Stack Overflow or by Simon Crabtree
Published on 2010-06-16T15:32:42Z Indexed on 2010/06/16 16:32 UTC
Read the original article Hit count: 268

I've been reading Greg Young and Udi Dahan's thoughts on Command Query Responsibilty Separation and a lot of what I read strikes a chord with me. My domain (we track vehicles which are doing deliveries) has the concept of a Route which contains one or more Stops. I need my customers to be able to set these up in our system by calling a webservice, and then be able to retrieve information about a Route and how the vehicle is progressing.

In the past I would have "cut-down" DTO classes which closely resemble my domain classes, and the customer would create a RouteDto with an array of StopDto(s), and call our CreateRoute webmethod, passing in the RouteDto. When they query our system by calling the GetRouteDetails method, I would return exactly the same objects to them. One of the appealing aspects of CQRS is that the RouteDto might have all manner of properties that the customer wants to query, but have no business setting when they create a Route. So I create a separate CreateRouteRequest class which is passed in when calling the CreateRoute "command", and a Route DTO class which gets returned as a query result.

class Route{
    string Reference;
    List<Stop> Stops;
}

But I need my customer to provide me with Route AND Stop details when they create a route. As I see it I could either...

Give my CreateRouteRequest class a Stops(s) property which is an array of "something" representing the data they need to provide about each stop - but what do I call this class? It's not a Stop as that's what I'm calling the list of DTO inside my Route DTO, but I don't like "CreateStopRequest". I also wonder if I'm stuck in a CRUD mindset here thinking in terms of master-detail information and asking the customer to think like that too.

class CreateRouteRequest{
    string Reference;
    ...
    List<CreateStopRequest> Stops;
}

or

They call CreateRoute, and then make a number of calls to an AddStopToRoute method. This feels a bit more "behavioural" but I'm going to lose the ability to treat creating a route including its stops as a single atomic command. If they create a Route and then try to add a Stop which fails due to some validation problem they're going to have a partially correct Route.

The fact that I can't come up with a good name for the list of "StopCreationData" objects I'd be working with in option 1, makes me wonder if there's something I'm missing.

© Stack Overflow or respective owner

Related posts about ddd

Related posts about cqrs

  • CQRS at Jax Code Camp 2012

    as seen on ASP.net Weblogs - Search for 'ASP.net Weblogs'
    Continuing my CQRS world tour...I gave my CQRS presentation at the Jax Code Camp 2012 this past Saturday.  It was a great crowd with lots of representation from the wicked smart engineers at Feature[23] and others from the Jacksonville developer community. If you'd like to take a… >>> More

  • CQRS without using others patterns

    as seen on Programmers - Search for 'Programmers'
    I would like to explain CQRS to my team of developers. I just can't figure out how to explain it in the simplest way so they can implement the pattern rapidly without any others frameworks. I've read a lot of resources including video and articles but I don't find how to implement CQRS without using… >>> More

  • Domain queries in CQRS

    as seen on Stack Overflow - Search for 'Stack Overflow'
    We are trying out CQRS. We have a validation situation where a CustomerService (domain service) needs to know whether or not a Customer exists. Customers are unique by their email address. Our Customer repository (a generic repository) only has Get(id) and Add(customer). How should the CustomerService… >>> More

  • CQRS - The query side

    as seen on Stack Overflow - Search for 'Stack Overflow'
    A lot of the blogsphere articles related to CQRS (command query repsonsibility) seperation seem to imply that all screens/viewmodels are flat. e.g. Name, Age, Location Of Birth etc.. and thus the suggestion that implementation wise we stick them into fast read source etc.. single table per view mySQL… >>> More

  • CQRS event versioning

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Versioning If your events changes you would create a new version of that event, and keep the old ones. To keep your domain code form being bloated with handling of all versions of events you would basically introduce a component that converts your events from previous to newer versions, and then… >>> More