質問

I am using the EventStore and CommonDomain frameworks made by J Oliver. I have notices that when I create a snapshot, it is not being passed to my aggregate factory and I am wondering why. This is my aggregate factory method constructing aggregates:

public IAggregate Build(Type type, Guid id, IMemento snapshot)
{
    ConstructorInfo constructor = type.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(Guid) }, null);
    IAggregate aggregate = constructor.Invoke(new object[] { id }) as IAggregate;
}

The snapshot parameter is null when it should be filled with a snapshot since when I add this to the method:

Snapshot snapshotContainer = _store.Advanced.GetSnapshot(id, int.MaxValue);
snapshot = snapshotContainer == null ? null : snapshotContainer.Payload as IMemento;

it shows me that snapshot is filled. What is going on here?

役に立ちましたか?

解決

OK I have found the problem, apparently the GetById method of the EventStoreRepository passes version 0 to the underlying method it overloads. So in essence it will try to load the snapshot till version 0 which obviously does not return a snapshot.

I changed my command handler by adding the int.MaxValue as extra parameter when retrieving an aggregate and now my aggregate factory gets the snapshot passed.

When I look further, I see that the latest nuget package contains this bug that affects other people as well: https://github.com/joliver/CommonDomain/issues/27

It has been updated in the repository; https://github.com/joliver/CommonDomain/commit/0fb51c7516ff06fae032aa04dbfdd0f242f86991 but not released it seems. Hopefully it gets updated some day.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top