Hello, im quite confused nowadays with the DDD principles, to put it compact i’ll use simple example:
Consider the validator aggregate which validates some commands, this validator needs to keep consistency with the configuration values, lets say i have validator for submitting a post, if user wants to submit a post it is whether the last submission date (for all of the requests) is greater than 30 seconds.
`
Validator {
lastSubmit: Long
minDelay: Long
void handle(changeConfig:NewConfig){
apply(configChanged)
}
void handle(validatePost: Post){
if (currentTime - lastSubmit < minDelay){
apply(success)
}
}
void on(evt:ConfigChanged){
minDelay = evt.delay
}
void on(evt: PostSuccess){
lastSubmit = currentTime
}
}
`
Now, as you can see that such aggregate is a single instance here, it doesn’t have multiple aggregate instances.
I’m familiar also with domain services, which could be used in this scenario but i’ve also heard about anemic domain model? It’s like even if i do implement it with domain service approach i would need to store the config somewhere and i dont’t really enojoy the idea that i would need to create specific database entry for it when i could just use axon’s aggregate repository to store it.
So it comes down to two questions:
First, are the domain services good approach for such things? Even if how to keep it simple, and make sure that consistency is kept between changing some rule and checking it.
Second, if i can create the aggregate such that, how would i make sure that only one instance of it is handled, eg what is the good spot to initialize it with some static aggregate id or maybe make the commands without aggregate id but how would i easily create the aggregate with constant id on demand when client sends the command?
At this moment im initializing the aggregate with constant id when my application starts (it obviously fails to create aggregate on each succeeding restart, but that’s intended) and every command targets that constaint id.
Many thanks!