Hello everybody,
I have a question regarding the commands and command handlers. In my project I have a large number of classes which are look almost the same, something like in example below:
public class SomeClass {
private String id;
private String name;
private List list;
…
}
and I have only a small number of commands to process CreateObject, RenameObject, DeleteObject, AddValueToList, RemoveValueFromList, but of course I want to do this for every class type. Imagine that I have 20 different classes, then (since generic commands are not supported by command bus) I need to create 20 command handlers and 20*6 different commands. It’s not difficult, but this is something that I want to avoid.
My idea was to implement only 6 generic commands, but include the class type to each command, so for example the CreateObject command will look as follows:
public class CreateObjectCommand {
@TargetAggregateIdentifier
public final String rootAggregateId;
public final String name;
public final Class<?> aggregateType;
…
}
then I can have only one command handler, which must be able understand the “aggregateType” and create an object of specified type.
Is it actually a good approach? Does anyone had similar problem? What you would suggest to do in that case?
Thank you,
Vitali