Having an aggregate root User
modeled as NServiceBus Saga
User.cs
public class User {
....
public string Rename(string name) {
.// some validation logic
}
...
}
UserSagaData.cs
public class UserSagaData : ContainSagaData
{
public User User { get; set;}
}
UserSaga.cs
public partial class UserSaga : Saga<RenameUser>
{
...
public async Task Handle(RenameUserimportAttendees, IMessageHandlerContext context)
{
Data.User.rename(...
}
...
}
Now i have a requirement to accept RenameUser command via REST API and give the feedback in HTTP Response, hence sending RegisterUser
to message broker from Controller.Action is not an option. I need to perform command synchronously, get feedback and send http response.
First thing that came to mind is to use ISagaPersister
, that is, retrieve saga by id, then invoke a command and then persist saga back to the datastore with ISagaPersister
(which takes care of optimistic locking). Any thoughts on that ?
Is there alternative solutions to this problem ?