Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objects composition of NEventStore components for DI

I'm adding NEventStore to my existing project and I'm using DI.

I'd like to have an instance of CommonDomain.Persistence.EventStore.IRepository injected into my MVC controller. The only implementation of this interface is EventStoreRepository.
This class depends on IConstructAggregates and the only implementation I find is AggregateFactory which is marked as internal, located in test project and has very strange file name.

Am I not supposed to use IRepository? (why is it marked as public and not consumed by any of the internal code?)
I'm looking on sample project here and IRepository used for manipulating of the aggregates.

Or should I implement IConstructAggregates myself?

like image 637
trailmax Avatar asked Nov 10 '14 00:11

trailmax


1 Answers

I'm struggling with the same thing, I think the short answer is:

If you're not using snapshots, the implementation in the test project would work fine. In fact, I'd add some code to throw an exception if you were given a snapshot.

If you are using snapshots, you'd have to use an approach similar to the one at the end of the one described here: http://williamverdolini.github.io/2014/08/20/cqrses-neventstore-snapshots/

Essentially, the issue is that the object that you'd return from IConstructAggregates will have the event stream replayed on it starting at the version immediately following the snapshot that is passed in.

Just a guess, but I think the reason this may not be "officially" implemented in CommonDomain is:

  • If you have Aggregates that support snapshots, you have to implement GetSnapshot() on them anyway, and you'd want to build an IConstructAggregates implementation that can re-hydrate those Aggregates somehow (maybe an ISupportSnapshots interface?)

  • It's possible that you'd want to use your DI container to build your Aggregate rather than just Activator.CreateInstance<T>().

Looks like this snippet of code here uses the same logic as the AggregateFactory from the test project: - http://pastebin.com/cFESMiTz

like image 59
Jeff Harris Avatar answered Oct 10 '22 12:10

Jeff Harris