【问题标题】:J Oliver EventStoreRepository is not returning snapshotsJ Oliver EventStoreRepository 不返回快照
【发布时间】:2020-10-27 19:07:54
【问题描述】:

我正在使用 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;

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

【问题讨论】:

    标签: c# snapshot event-sourcing neventstore


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-05
      • 2021-07-03
      • 2017-03-24
      • 2020-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多