Hi everybody!
There are several operations in my current project which include adding media content (user adds userpic, etc). Now I see two ways how to implement file persistence in command->commandhandler->eventhandler pipeline:
1) Add byte array to Command and push it through Domain Object (User for example) and finally make it a part of generated event which will be persisted to read db (mongodb in my case). Why I don't like this approach:
a) Aggregates become very heavy (imagine that we have about 30 images and we should load all them to make some action on aggregate root)
b) Storage space needed to persist files doubled
c) Duplication of files if we want to add one file to several roots
2) Save file to special file storage (in Command handler or even before command processing), get file id (ObjectId in Mongodb GridFS) and work with file id in DomainObject and EventHandlers. Why I don't like this:
a) It breaks the rule that we update our read model in EventHandler
b) It adds new component to persist files
So what is the best way in CQRS/EventSourcing projects to persist files? Thanx in advance for your suggestions.