efacilitation/eventric

Feature request: Ability to specify the id when creating an aggregate

Closed this issue · 6 comments

A very typical allowance of eventsourcing frameworks is the ability to specify custom ids when creating aggregates. Currently, aggregate ids are generated automatically within Eventric using the uuidGenerator.

As an example I'd propose something like the following (where f3513994-5448-4f38-b9f2-62ff17e14661 is the desired aggregate id):

todoContext.addCommandHandlers

  CreateTodo: ({title}) ->
    @$aggregate.createWithId 'Todo', 'f3513994-5448-4f38-b9f2-62ff17e14661',
      title: title
    .then (todo) ->
      todo.$save()

I'd be happy to submit or assist on a pull request to add support for this.

@coreyjonoliver Thank you for the feature request.

You are absolutely right. We just recently learned that generating entity IDs (and therefore aggregate root entity IDs) internally is actually an anti pattern.

I would suggest to make passing in an entity ID the default behaviour. However I´m not sure about the syntax. And we would have to do some refactoring in our project using eventric.

What do you think @medialwerk ?

Yes, i agree with you @alexlawrence. I would change the default interface to @$aggregate.create AggregateName, id or even better to an architecture were it is possible to instantiate the Aggregate directly without a factory method. What do you think about the syntax alex?

But I do not know when we will have the capacities to make one of these changes. I would be fine for now with the quicker solution to simply add the id to the create function. But as alex says, it would lead to some refactorings in our project. I think @alexlawrence and i should talk about that on the phone these days and attach after that our conclusion here.

@coreyjonoliver Sorry it took so long but now we have an update.

@medialwerk and I talked about this issue. We want to achieve the following goals:

  • add the possibility to provide an (aggregate root) entity ID when creating an aggregate
  • keep the number of interfaces for aggregate creation at a minimum
  • prevent any refactoring in our project using eventric

Therefore we suggest to add an optional id parameter to the @$repository service injected into Context objects and to the AggregateRepository instances.

Can you decide on the syntax and provide a pull request (including specs)?

Thank you

@alexlawrence Sorry for the delayed response. Let me put something together and open up a pull request.

@alexlawrence @medialwerk I opened up a pull request a few weeks back: #48. Let me know if you have any comments/suggestions.

@coreyjonoliver Sorry for the delay. At the moment I´m not actively developing on eventric.