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

Command Handling questions #37

Open
truegoodwill opened this issue Mar 13, 2024 · 1 comment
Open

Command Handling questions #37

truegoodwill opened this issue Mar 13, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@truegoodwill
Copy link

Command handling often requires dependency injection to perform tasks associated with, for example, validating a command and kicking off other processes.

For example, handling the ChangeEmail command might involve first checking an injected EmailReservationService to verify the email isn't already taken by another user.

Grain state can't get services injected. Therefore the actor classes as used in this opinionated framework also cannot use injected services to validate/handle their commands.

Therefore I write a UserCommandHandler class separately from the UserAggregate (state) class. A command comes to the event-journaled UserGrain which has reconstructed the UserAggregate from past events, and has had the UserCommandHandler injected. It then passes both the state and the command to the UserCommandHandler, which goes through all the hoops associated with validating and processing a command including calls to other injected services. Then the command handler returns an IEnumerable containing all the events to be applied to the state/journaled grain.

I'm VERY interested in seeing where this project goes, but I'm afraid for me at the moment, there's not the correct wiring between the grain, the state and injected services yet. Thank you. And I'm really happy to demo further if you're interested in knowing how I work. And if you can simplify me, that'd be good too :)

@truegoodwill truegoodwill added the bug Something isn't working label Mar 13, 2024
@truegoodwill
Copy link
Author

EventSourced objects maintain a sequential event count as you know. All my command objects have an "ExpectedVersion" property so the command handler can reject the command if the grain state has already moved on due to concurrent commands from elsewhere.

To make things smoother, my actor grains return the state's new version id after every command, successful or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant