J Oliver EventStoreRepository未返回快照

时间:2013-08-21 18:32:32

标签: c# snapshot event-sourcing event-store

我正在使用J Oliver制作的EventStore和CommonDomain框架。我注意到,当我创建快照时,它没有传递给我的聚合工厂,我想知道为什么。这是构建聚合的聚合工厂方法:

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;
}

当我将快照参数添加到方法时,快照参数为空:

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

它向我显示快照已填满。这是怎么回事?

1 个答案:

答案 0 :(得分:0)

好的,我发现了问题,显然EventStoreRepository的GetById方法将版本0传递给它重载的基础方法。所以本质上它会尝试将快照加载到版本0,这显然不会返回快照。

我通过在检索聚合时添加int.MaxValue作为额外参数来更改我的命令处理程序,现在我的聚合工厂将传递快照。

当我进一步观察时,我发现最新的nuget包中包含这个影响其他人的错误: https://github.com/joliver/CommonDomain/issues/27

它已在存储库中更新; https://github.com/joliver/CommonDomain/commit/0fb51c7516ff06fae032aa04dbfdd0f242f86991 但似乎没有发布。希望它有一天会得到更新。