开发者

CQRS, should commands/events parameters contains everything we need?

my application uses CQRS, I have a case where I have a command "AddApplicationToGroupCommand" with following parameters:

class AddApplicationToGroupCommand
+ Guid GroupId; // AggregateRootId
+ string ApplicationName;

This command pass through my aggregate, then an event is published; handled in my EventHandler and finally persisted 开发者_如何学Cin my database.

My question is about best practices. What I want in the end is that my EventHandler insert in the table application with the following parameters

Table Applications
int ApplicationId
varchar(255) ApplicationName
varcher(255) GroupName

As you see, I need the GroupName when I'm gonna insert in the table. So in order to do this, I'm in front of two ways of doing this.

Either I pass my groupId as I've done above, then in my EventHandler, I'll have to query my Group table in order to retrieve the name of groupId. Either I pass GroupName in my command's parameters above, then in my eventHandler I can directly do

myContext.Applications.Insert(applicationName, groupName)

What says CQRS ?

Thanks guys.

[Edited for more clarification about my goal]


I'd suggest it's more about your domain rather than CQRS.

If you're following DDD, then it would depend on aggregates - is the Group a seperate Aggregate ? If so then yes you'll be dealing with Ids (generally) and would look up the releveant data in your command using a Reporting query to find the name.

If it's not a different aggregate then having the group name available doesn't violate such issues.

I would also argue whether an aggregate or not the above are best-practice guidelines, there's no silver hammer. Or, slightly more clearly, if you really need the group name, pass it in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜