Objects composition of NEventStore components for DI
Asked Answered
D

1

6

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?

Dubuffet answered 10/11, 2014 at 0:10 Comment(0)
I
3

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

Inositol answered 22/11, 2014 at 0:46 Comment(7)
I think I have found the reason for this class not to be publicly-supported: it seems to be incomplete and not properly tested. I'm having a range of problems with this repository and already filed a bug-report: github.com/NEventStore/NEventStore/issues/376Dubuffet
And no, no snapshots for me, but I think I'll have to avoid this class anyway, as I'm stumbling into major issues using it -(Dubuffet
I think I'm going to end up using something like geteventstore.com and using a modified-version of the CommonDomain project. I'm finding a few things there need a little bit of adjustment to work for my situation.Inositol
Yep, we have decided against using NEventStore in production for a new project. Too many issues unfortunately -(Dubuffet
Have you considered using something like: github.com/yreynhout/AggregateSource ? It looks better thought-through than CommonDomain.Inositol
Nope, have not seen this one. Will take a look. Thanks for the link!Dubuffet
Actually...I've realized this goes a bit too far in the other direction for me :-) But it's helpful to see that you can use something other than CommonDomain with NES -- personally, I'm doing a sort of blend of a few approaches and hoping to use geteventstore.comInositol

© 2022 - 2024 — McMap. All rights reserved.