Skip to content

The Write Lock

Tomas Lycken edited this page Oct 30, 2017 · 1 revision

In order to ensure that you don't have multiple threads adding events simultaneously, your event store should depend on the write lock. There is an interface IWriteLock and a default implementation WriteLock that just wraps AsyncLock from Stephen Cleary's AsyncEx suite:

var writeLock = new WriteLock();

The default implementation also locks per stream, which means you can commit events to different streams simultaneously, but commits to the same stream have to wait for each other (and first one there will win).

It is very important that the write-lock instance is singleton across the application. Otherwise, it won't do much good...