Re: [axonframework] Modeling aggregates - go for separate ones or one bigger?

87 views
Skip to first unread message

Allard Buijze

unread,
May 31, 2015, 2:45:18 PM5/31/15
to axonfr...@googlegroups.com
Hi,

there is a third option. You can have them as separate aggregates, even without a Domain Service. A questionnaire can reference an Event (this aggregate name will definitely lead to a decent amount of confusion ;-) ). This would primarily reflect in the query model. In the fields of the Event (aggregate) itself, you don't have to see it. The same would apply for Survey.

You asked: "So how should I reference Survey and Questionnaire, having only EventId at the time?" If you don't have the aggregate ID, there is only one way to obtain it: do a query. That's what the query model is for.

Hope this helps.
Cheers,

Allard





On Fri, May 29, 2015 at 12:48 PM, Sławomir Nowak <slnow...@gmail.com> wrote:

I'm not sure whether I should ask this question here, since it's more like a design question than framework one. But I'm using axon framework to implement this, so maybe let's try... ;)

Imagine the following:
You have an Event. This is the main concept of your application, it acts like a state machine.
It could be in a PROPOSED state - in that case, people should be able to vote for and against it (for example: AxonFramework Workshop - as an end user I would like to say whether I would participate in this workshop or not (voting up/down)). 
So surely there is a concept called "InterestSurvey". 

Now, besides of voting, as a person which organizes this event, I would like my potential participants to answer few questions - for example "What's your Java skill?". 
In my domain, currently I call it "Questionnaire".  Questionnaire is something optional.

Now:
These concepts are clearly related to Event. But on the other hand, since Event is my main aggregate, also acting as a state machine, I consider putting InterestSurvey and Questionnaire inside Event as a bad idea. So I'm about to implement them as a seperate AggregateRoots. 

And the problem:
What is responsible for starting and ending Survey and Questionnaire? 

1) At the beginning I thought maybe Event should act as factory for those two. 
Something like: 
final Survey survet = event.startSurvey(...)
final Questionnaire = event.startQuestionnaire(...)
event.stopSurveying()
those methods also should change event's state. 

But it causes few problems. My CommandHandler needs to know about 3 repositories - for Event, Survey and Questionnaire. As far as I know, it is impossible to test it with
 GiventWhenThenFixture

as it references more than one aggregate root at the time.

2) What about a domain service? 
I could create a DomainService which:
 - changes Event's states
 - creates both aggregates
 - ends them when needed. 

I don't like this idea mainly because I'm moving event's behaviour somewhere else. There's another problem - AFAIK axon repositories don't allow you to query by something else than aggregate ID. So how should I reference Survey and Questionnaire, having only EventId at the time?

Anny suggestions?

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages