开发者

CQRS Commands as Models for POST actions

开发者 https://www.devze.com 2023-03-21 22:16 出处:网络
I\'m getting started with CQRS, and though开发者_JAVA技巧t It would make the most sense to use the Command object as the Model on my forms.I can take advantage of some of the client-side validation fo

I'm getting started with CQRS, and though开发者_JAVA技巧t It would make the most sense to use the Command object as the Model on my forms. I can take advantage of some of the client-side validation for the commands using DataAnnotations, client-side validation, makes it pretty clean...

My question... does this raise any problems? If my command does not have a default constructor, will this make this process impossible? Do I need to create my own CommandModelBinder that can constructor inject the aggregate ID?

Your thoughts, I can't find this technique anywhere and Im assuming because it doesn't work.


I'd recommend that you take a look at Greg Young's article on task-based UI's on how DTOs and Messages interact with your system (both client-side and server-side).

I agree with Sebastian that your Commands will match exactly with what your user interface will look like. As a result, you'll probably need to have separate DTO/Model classes and Commands. That's really not a bad thing as your Model is really the result of your query-side of the system and really shouldn't be an exact duplicate of the messages you're sending into the system.

Also, by keeping your commands separate from your model, your concern about Command constructors goes away. Your controller just collects information from the client, constructs the command and then submits it.

If you're getting started with CQRS, Greg's site (cqrsinfo.com) is pretty good, especially his 6 1/2 hours video. Yes, it's 6 1/2 hours, but it really is a great introduction and overview of what CQRS is all about. It helped me out tremendously.

Hope this helps!


Using a POST to send your command to the domain command handlers seems sensible. But it's unlikely to be the exact object you bind your interface to. Commands in the interface (e.g. Mouse clicks) will become domain commands (create user). Your GUI is most likely to be bound to the results of a Query.


For the reasons you mentioned you would create View Models which are basically your dto's sent between client and server. This way you can use all the mvc goodness like modelbinding, data annotations, etc. In you controller you would then create the command and send the command to the service bus.

I think this will help you separate concerns a little better and it would be easier to test in my opinion.

0

精彩评论

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