JOliver 的 EventStore:使用 ServiceStack 序列化程序时无法读取事件
使用 ServiceStack 时,EventMessage.Body 不会反序列化回原始对象。相反,EventMessage.Body 是一个 JSON 字符串。
重现:
- 打开 EventStore 项目并导航到 EventStore.Example 项目
- 将 EventStore.Serialization.Json 引用替换为对 EventStore.Serialization.ServiceStack 的项目引用
- 关闭 EventStore.Example 项目上的程序集签名
- 将 MainProgram.WireupEventStore 更改为 .UsingServiceStackJsonSerialization()
- 在 MainProgram.Main() 末尾附近添加以下代码:
-
var stream = store.OpenStream(StreamId, 0, int.MaxValue);
var myFirstEvent = (SomeDomainEvent) (stream.CommittedEvents.First().Body);
Console.Out.WriteLine("MyFirstEvent.Value=" + myFirstEvent.Value);
EventMessage.Body isn't deserialized back into the original object when using ServiceStack. Instead EventMessage.Body is a JSON string.
To reproduce:
- Open the EventStore project and navigate to the EventStore.Example project
- Replace the EventStore.Serialization.Json references with project references to EventStore.Serialization.ServiceStack
- Turn off assembly signing on EventStore.Example project
- Change MainProgram.WireupEventStore to .UsingServiceStackJsonSerialization()
- Add the following code near the end of MainProgram.Main():
-
var stream = store.OpenStream(StreamId, 0, int.MaxValue);
var myFirstEvent = (SomeDomainEvent) (stream.CommittedEvents.First().Body);
Console.Out.WriteLine("MyFirstEvent.Value=" + myFirstEvent.Value);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果它是一个字符串并且您期望 SomeDomainEvent 您可以使用 ServiceStack 的 FromJson 扩展方法,即:
If it's a string and you're expecting SomeDomainEvent you could use ServiceStack's FromJson Extension method, i.e: