views:

153

answers:

1

Hi all,

Here is the situation, in order to support our legacy system, we need to insert to a table whenever a user logs in. This is basically an CRUD operation, so it doesn't really make sense to create repository/entity/command/event for this since this doesn't tie to any business rules at all. The only benefit to create a CQRS command is that this database write can happen asynchronously under that model. Which is a better route to take?

  • Use CQRS, and then call a stored proc. when handling that command?
  • Just call database directly in the controller (I am using asp.net mvc)
+1  A: 

If you are using (and persisting) events for possible playback, then it makes sense to do the writing to a legacy DB as part of an event handler (think "gateway"). If you need to replay this event in the future you can swap in a fake handler that doesn't reinsert the record.

Your controller should really only be a translation layer between and HTTP request and a command for your domain. Writing to a DB (even legacy, non-domain access) doesn't really make sense there, IMHO. Putting the logic in an event handler makes the interaction very explicit.

Ryan