任何人都可以为我指出 NEventStore 3.0 的 protobuf-net 序列化程序吗?
我遇到了麻烦,我认为主要是由于事件存储 3 中的序列化将事件正文和标题包装在 EventMessage 中。
我不确定如何正确设置自定义序列化程序。
最佳答案
这是完全未经测试的猜测,基于对 github 的简要介绍,但看起来您想使用连接 API 来指定自定义序列化程序,例如:
var store = Wireup.Init()
.UsingSqlPersistence("Name Of EventStore ConnectionString In Config File")
.InitializeStorageEngine()
.UsingCustomSerialization(mySerializer)
... etc
其中
mySerializer
是实现 ISerialize
接口(interface)的类型的实例。看起来这应该有效:class ProtobufSerializer : EventStore.Serialization.ISerialize
{
public void Serialize<T>(Stream output, T graph)
{
ProtoBuf.Serializer.Serialize<T>(output, graph);
}
public T Deserialize<T>(Stream input)
{
return ProtoBuf.Serializer.Deserialize<T>(input);
}
}
(所以很明显
mySerializer
在这里将是一个 new ProtobufSerializer()
)