如何使用J Oliver的EventStore库? [英] How to use J Oliver's EventStore library?

查看:77
本文介绍了如何使用J Oliver的EventStore库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究一个以J Oliver's EventStore和mongo为持久层的新项目的Event Sourcing,但遇到了一些问题:

I've been looking into Event Sourcing for a new project with J Oliver's EventStore and mongo as the persistence layer but have come across a few questions:


  1. 在尝试事件源采购之前,我的域一直保存到数据库,并且我一直在使用Udi的域事件模式对我来说非常有效,NHibernate管理工作单元。但是,我最终完成了一个工作单元,该工作单元可能会影响多个集合,例如

  1. Previous to trying event sourcing my domain persisted to a db and I've been using Udi's domain events pattern which has worked really well for me with NHibernate managing the unit of work. However I've ended up with one unit of work that can affect more than one aggregate eg.

我结帐我的购物篮汇总,它引发一个事件,处理程序通过创建一个发票汇总来响应该事件,而发票汇总又反过来引发一个事件(这仅是示例)

I "checkout" my shopping basket aggregate which raises an event for which a handler responds by creating an invoice aggregate which in turn raises an event (this is an example only)

在这种情况下,我有一个工作单元可以更改两个聚合的根-在事件存储中,我可以将引发的事件添加到两个不同的事件流中,但它们不会以原子方式持久化(第一个可能成功而第二个失败)。那么人们如何避免这种情况的发生?

In this case I have one unit of work that alters two aggregate roots - in the event store I could get the events raised added to two different event streams but they would not be persisted in an atomic way (the first could succeed and second fail). So what do people do to aviod this from happening?

在github主页上,它建议您可以使用流畅的界面来配置EventStore,但是当我下载了源代码,对其进行了编译,并在示例中查看了wireup类似乎不可用的情况-它是否在其他分支中? (我有主)

On the github home page it suggests that you can use a fluent interface to configure the EventStore, however when I download the source, compile it and look in the example the wireup class doesn't seem to be available - is it in a different branch? (I have master)

处理IStoreEvents impl的推荐方法是什么?作为类似于Nhibernates会话工厂的单例吗?

What is the recommended way to handle the IStoreEvents impl? As a singleton similar to Nhibernates session factory?


推荐答案


  1. 在给出的示例中,实际上已经发生了多个工作单元。修改汇总后,将调度事件。

  1. You've actually got multiple units of work occurring in the example you gave. When an aggregate is modified it dispatches an event. Something else listens to that event and handles another unit of work and so on.

EventStore的设计方式仍然可以容纳您的情况,但这将是三个独立的工作单元。您只需插入Udi的DomainEvents救助您自己的IPublishEvents实现中的解决方案,并在AsynchronousCommitDispatcher中运行它。在真正的DDD中,单个聚合是一个工作单元-根据定义,这是一致性边界。

The way the EventStore is designed, it can still accommodate your scenario but it would be three separate units of work. You would just plug in Udi's DomainEvents "Salvation" solution into your own implementation of IPublishEvents and run that inside of the AsynchronousCommitDispatcher. In true DDD a single aggregate is a unit of work--by definition this is the consistency boundary.

大约8个小时前,我做了一个推送中包含流利的内容作为编译的一部分。尝试从master那里获取最新信息。

About 8 hours ago I did a push that has the fluent stuff as part of the compilation. Try pulling down the latest from master.

IStoreEvents设计为多线程的,因此您可以在应用程序中安全地将其配置为单例。当您从IStoreEvents打开会话时,该会话是单线程的,不应在应用程序中的线程之间共享。

IStoreEvents is designed to be multithreaded so you can safely configure it as a singleton within your application. When you open a session from IStoreEvents, the session is single threaded and should not be shared across threads within your application.

这篇关于如何使用J Oliver的EventStore库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆