You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 :)
The text was updated successfully, but these errors were encountered:
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.
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 injectedEmailReservationService
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 theUserAggregate
(state) class. A command comes to the event-journaledUserGrain
which has reconstructed theUserAggregate
from past events, and has had theUserCommandHandler
injected. It then passes both the state and the command to theUserCommandHandler
, which goes through all the hoops associated with validating and processing a command including calls to other injected services. Then the command handler returns anIEnumerable
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 :)
The text was updated successfully, but these errors were encountered: