protected override void PreStart()
{
base.PreStart();
_snapshotCollection = new Lazy<IMongoCollection<SnapshotEntry>>(() =>
{
var connectionString = new MongoUrl(_settings.ConnectionString);
var client = new MongoClient(connectionString);
var snapshot = client.GetDatabase(connectionString.DatabaseName);
var collection = snapshot.GetCollection<SnapshotEntry>(_settings.Collection);
if (_settings.AutoInitialize)
{
collection.Indexes.CreateOneAsync(
Builders<SnapshotEntry>.IndexKeys
.Ascending(entry => entry.PersistenceId)
.Descending(entry => entry.SequenceNr))
.Wait();
}
return collection;
});
}