Composition of NEventStore Component Objects for DI

I am adding NEventStore to my existing project and I am using DI.

I would 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 only the implementation that I find is the AggregateFactory , which is marked as internal, is in the test project and has a very strange file name.

Shouldn't I use IRepository ? (why is it marked as open and not used by any internal code?)
I am looking at a sample project here and an IRepository used to manage aggregates.

Or should I implement IConstructAggregates ?

+6
source share
1 answer

I am struggling with the same, I think the short answer is:

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

If you use snapshots, you will need to use an approach similar to the one described at the end of the one described here: http://williamverdolini.imtqy.com/2014/08/20/cqrses-neventstore-snapshots/

In fact, the problem is that the object that you will return from IConstructAggregates will play a stream of events on it , starting with the version immediately after the snapshot that is passed to .

Just guessing, but I think the reason this cannot be β€œofficially” implemented in CommonDomain is:

  • If you have aggregate files that support snapshots, you still need to implement GetSnapshot() , and you want to build an IConstructAggregates implementation that can somehow moisten these aggregates (maybe the ISupportSnapshots interface?)

  • You might want to use your DI container to create your aggregate, not just Activator.CreateInstance<T>() .

It looks like this piece of code uses the same logic as the AggregateFactory from the test project: - http://pastebin.com/cFESMiTz

+3
source

Source: https://habr.com/ru/post/977957/


All Articles