Herman
Herman

Reputation: 3024

Mixing Transaction Script pattern with DDD/CQRS

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?

Upvotes: 1

Views: 1349

Answers (1)

Ryan
Ryan

Reputation: 4313

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.

Upvotes: 3

Related Questions