CQRS questions

110 views
Skip to first unread message

Christian Setzkorn

unread,
Jan 22, 2013, 5:00:56 AM1/22/13
to S#arp Architecture
Hi,

I have a few questions to:

https://github.com/sharparchitecture/Sharp-Architecture-Cookbook/wiki/Using-commands

(1) The link to CQRS seem to be broken. Could you please be so kind
and provide a recommended alternative?

(2) I have a version of the Cookbook, which implements the
AddCustomerAddressHandler but never actually uses it. Is there some
complete code where a handler is actually used and also unit tested?

Any feedback would be very much appreciated. Thanks.

Christian

csetzkorn

unread,
Jan 22, 2013, 5:42:01 AM1/22/13
to sharp-arc...@googlegroups.com
I think I found what I am looking for. The CustomerController in the cookbook gets the ICommandProcessor injected.

Still, I would appreciated any more complete code examples with unit testing, if there are any. Thanks a lot.

Christian

Christian Setzkorn

unread,
Jan 22, 2013, 6:10:21 AM1/22/13
to sharp-arc...@googlegroups.com
I am also wondering where you usually put the result classes which
inherit from CommandResult.

In other words looking at the cookbook example:

https://github.com/sharparchitecture/Sharp-Architecture-Cookbook/wiki/Using-commands

where do you put:

ChangeCustomerAddressResult

Thanks.

Christian
> --
> You received this message because you are subscribed to the Google Groups
> "S#arp Architecture" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sharp-architecture/-/TC7c0tk5ySkJ.
> To post to this group, send email to sharp-arc...@googlegroups.com.
> To unsubscribe from this group, send email to
> sharp-architect...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sharp-architecture?hl=en.

Seif Attar

unread,
Jan 22, 2013, 8:04:26 PM1/22/13
to sharp-arc...@googlegroups.com
There are not any helpers AFAIK for this, but I don't see what is difficult about testing the handlers, it is just a class that you call the Handle method on with a command object. What might be tricky to test is the DomainEvents.Raise and asserting that an event is raised, because you would need to mock the ServiceLocator.GetAllInstances to return a mock handler that you can assert on (something along the lines of https://github.com/sharparchitecture/Who-Can-Help-Me/blob/master/Solutions/MSpecTests.WhoCanHelpMe/ServiceLocatorHelper.cs), if you think it would be a good idea to add this as some sort of testing helper add an issue for it, and hopefully we'll get to it by 3.0.

As for the CommandResult, I would put them wherever you have the commands :) since they will be used in the same place. The cookbook Using-commands page you linked says:
"Commands, CommandHandlers and their Result live in the Controller Layer. A Command is sent to a Handler, and returns a result." but what happens if in one of your tasks needed to send the command? add a reference to the controllers in your tasks? don't think that is a good approach. But if you dont have tasks, and all you have is Controllers -> Handlers -> Load entities from repos and run code -> Publish Events, and you don't have any tasks that will be sending the command (removing the tasks project all together), then there is no harm in having the lot in the controllers project.Hope this makes sense.

The code in the cookbook has put them in Tasks, which I think is a better approach, in fact if no1 objects, I am going to change the wiki page :)

Seif Attar

unread,
Jan 22, 2013, 8:06:08 PM1/22/13
to sharp-arc...@googlegroups.com
BTW, I was looking at the code for TResult and noticed a possible issue if you want to provide any input on it (you also need to be aware of it)
Reply all
Reply to author
Forward
0 new messages