EasyEventSourcing icon indicating copy to clipboard operation
EasyEventSourcing copied to clipboard

Avoid "Default Constructor Dependency"

Open pietrom opened this issue 7 years ago • 2 comments

In the README you wrote I hate the default constructor dependency needed to build Aggregates and Process Managers in the IRepository. I am not sure how to remove it :(. I have tried removing it, handling first event of stream as a "special case" on rebuilding aggregates: I use (by reflection) a constructor with a signature like TAggregate(TEvent initEvent), constructor I use in the factory static method Create, too.

I tried an alternative approach, providing rebuilding functions of the form TEvent --> TAggregate and providing explicit rebuilders registration for initial events. This approach is less magic than using a specific constructor by reflection, but in my opinion it makes rebuilding logic and rebuilders registration more complicated and requires a full review of existing code; so I choose an approach that minimizes changes in existing code.

I would be happy to have your opinion about this (imho very interesting) topic.

pietrom avatar Aug 24 '18 15:08 pietrom

Thanks for this PR.

I have not worked in .net land for quite a bit and for me to merge this would probably be quote the time investment. I may get to it, but probably not soon.

SneakyPeet avatar Jun 25 '20 04:06 SneakyPeet

Why is the default ctor requirement a problem? It's the simplest ctor to use.

IMHO handling the first event of a series/stream of events as a special case only adds complexity to the code.

BjarkeMeier avatar Jun 07 '21 14:06 BjarkeMeier