Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use lambdas insterad of command objects? #160

Closed
olleharstedt opened this issue Feb 13, 2022 · 4 comments
Closed

Use lambdas insterad of command objects? #160

olleharstedt opened this issue Feb 13, 2022 · 4 comments

Comments

@olleharstedt
Copy link

Quick question, but is it possible to push lambdas or closures onto the command queue instead of command objects?

@frankdejonge
Copy link
Member

@olleharstedt it's possible, but I wouldn't recommend it. Message based architectures are all about communication and letting actors respond to commands or requests or events. Passing logic or behaviour around is quite in opposition of that. But since EventSauce doesn't ship with command infrastructure, you can do what you like of course.

@olleharstedt
Copy link
Author

Ah. I'm looking for a more lightweight way to remove side-effects from business logic, and I was thinking an event queue would fit. I'll keep looking. :) Thanks.

@frankdejonge
Copy link
Member

An event queue would fit, but the logic should be in the consumer, not the payload

@olleharstedt
Copy link
Author

olleharstedt commented Feb 13, 2022

I'm struggling to express a DSL in PHP without massive amounts of boilerplate. A builder pattern works best:

$user = new User();
// ... set properties
$st
  ->if(fn () => $user->save())
  ->then(fn () => /* Do something */)
  ->else(fn () => /* Throw exception? */);
// ... more logic
$st->run();  // Execute all events

I don't think it'd be ergonomic to create a command for every model and database interaction, like SaveUserCommand, SaveBlogCommand, etc.

Edit, oh, you use code generation for that. Neat. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants