在joliver/EventStore中使用MongoDB持久化引擎会导致错误Unknown discriminator value 'MyEvent'
。该问题仅在尝试加载所有事件以重播事件时才会出现,例如this.storeEvent.Advanced.GetFrom(new DateTime(2010, 1,1))
此问题是由ExtensionsMethods.cs引起的。
public class MyClassEvent : IDomainEvent { ... }
public static Commit ToCommit(this BsonDocument doc, IDocumentSerializer serializer)
{
if (doc == null)
return null;
var id = doc["_id"].AsBsonDocument;
var streamId = id["StreamId"].AsGuid;
var commitSequence = id["CommitSequence"].AsInt32;
var events = doc["Events"].AsBsonArray.Select(e => e.AsBsonDocument["Payload"].IsBsonDocument ? BsonSerializer.Deserialize<EventMessage>(e.AsBsonDocument["Payload"].AsBsonDocument) : serializer.Deserialize<EventMessage>(e.AsBsonDocument["Payload"].AsByteArray)).ToList();
var streamRevision = doc["Events"].AsBsonArray.Last().AsBsonDocument["StreamRevision"].AsInt32;
return new Commit(
streamId,
streamRevision,
doc["CommitId"].AsGuid,
commitSequence,
doc["CommitStamp"].AsDateTime,
BsonSerializer.Deserialize<Dictionary<string, object>>(doc["Headers"].AsBsonDocument),
events);
}
我的配置如下:
Wireup.Init()
.UsingMongoPersistence(connectionName, new DocumentObjectSerializer())
.UsingBsonSerialization()
.UsingAsynchronousDispatcher()
.PublishTo(this.container.Resolve<IPublishMessages>())
.Build();
但已经尝试了几乎所有类型的序列化选项。