Suppose there is a aggregate "Alert". I have a csv file contains Alerts data. I process a csv file and create a List of Alerts objects. Here, I can iterate list and create AlertCreatedCommand, Event sourced it and trigger event. So, what do you think on this approach? Is there any better approach?
But do you really need to create an aggregate? Is there any logic that would be realized by the aggregate? Or you need to create and event?
Add some additional information about use case to clarify what you want to do?
W dniu niedziela, 21 lipca 2019 07:53:28 UTC+2 użytkownik Abhijeet Tayade napisał:
Yes, I have to create AlertAggregate. There will be AlertService which creates CreateAlertCommand, AssignAlertCommand, AcceptAlertCommand and ApproveAlertCommand (other workflow related commandes) and its respective events. We want to leverage Event Sourcing for our AlertAggregate and have to send those events to downstream.
As I mentioned earlier, we have to create Alerts by reading csv file and have to publish CreateAlertCommand one by one.
It looks for me that you want to bootstrap your application with provided data at hand, there is nothing magic in creating bulk aggregates other than just dispatching commands that create them.
What i would do is to create an application service (command handler essentially, without specified target id), inside that command i would have information as to where to grab the data from, and then just dispatch the commands.
But yeah, i would not emit events from anywhere other than the aggregate itself.
Keep in mind that, yeah, you are doing your own unique thing and keep in mind that aggregates are not ‘data’ you really must have the behavior, if you are trying to work with some legacy system and create appropriate aggregates based on it, i think that it will just be fine.
Also, be aware of problems on your application side of things (the csv parsing), it might sometimes not work and not dispatch proper aggregate creation command, so you should also consider some model for retrying? hah, im just over complicating it now, just be aware of these things.