eventuous
eventuous copied to clipboard
Identity attribute for commands
Right now, in the app service, we explain how to get the aggregate id from a command:
OnNewAsync<V1.CreateTask>(
cmd => new ProjectTaskId(cmd.TaskId),
async (task, cmd, token) => { ... }
)
It seems a bit too verbose. We know the drill - the identity must be a non-empty string value. So, in theory, it can be simplified to use an attribute:
public record CreateTask([AggregateId] string TaskId, string Description);
The app service overloads without the first function would be able to check if the property is of type string on startup, ensure that it's not empty when it gets the command, and construct the identity instance of a given type as it has a default constructor. So, the call would look like:
OnNewAsync<V1.CreateTask>(
async (task, cmd, token) => { ... }
)