Let’s say I have a command handler that injects a state object:
@CommandHandler
fun handle(
command: Command,
@InjectEntity(idProperty = "property") state: State,
eventAppender: EventAppender,
) {
...
}
This requires me to have the idProperty set in my command. Otherwise, I will get a framework error.
I do not think this is ideal for at least 2 reasons:
- My command may be malformed, but I want to be able to handle the error inside my command handling method to output a functional exception.
- It may be (especially with more than 1 entity to be injected) that a an absent entity is not an invalid state. An event may have nullable relations in a DCB context, it requires only 1 non-nullable tag (if even that).
I encounter both of these reasons in our use cases.
So what I would like to do is the following:
data class Command(val property: String?, ...)
@CommandHandler
fun handle(
command: Command,
@InjectEntity(idProperty = "property") state: State?, // nullable
eventAppender: EventAppender,
) {
if(state==null) {
// handle nullability
}
}
Where the state resolves to `null` (or empty, if you want to go the optional route, which may make more sense in Java) in case the property in the command is null.
Is there in the current implementation a workaround for this? I have tried to build something, but I’m running into issues every time.