public EventStoreSettings( StoreSettings store, IReadOnlyDictionary <Type, object> aggregateFactories, SnapshotsSettings snapshots) { Store = store ?? throw new ArgumentNullException(nameof(store)); AggregateFactories = aggregateFactories ?? throw new ArgumentNullException(nameof(aggregateFactories)); Snapshots = snapshots ?? throw new ArgumentNullException(nameof(snapshots)); }
public void profile_snapshot_opt_out() { var sampleAggregateId = new SampleAggregateId(1); var aggregate = TestAggregateFactory.Create <SampleAggregate, SampleAggregate.State>(new SampleAggregate.State(), sampleAggregateId); aggregate.Create(); _sut.Save(aggregate, Guid.NewGuid(), null); int max = 20; for (int t = 1; t < max; t++) { aggregate.Touch(); _sut.Save(aggregate, Guid.NewGuid(), null); if (t == max - 5) { var snap = ((ISnapshotable)aggregate).GetSnapshot(); _eventStore.Advanced.AddSnapshot(new Snapshot("Jarvis", sampleAggregateId.AsString(), aggregate.Version, snap)); } } SnapshotsSettings.OptOut(typeof(SampleAggregate)); var sw = new Stopwatch(); sw.Start(); for (int c = 1; c <= 100; c++) { using (var repo = new RepositoryEx( _eventStore, _aggregateFactory, new ConflictDetector(), _identityConverter, NSubstitute.Substitute.For <NEventStore.Logging.ILog>())) { var loaded = repo.GetById <SampleAggregate>(sampleAggregateId); } } sw.Stop(); SnapshotsSettings.ClearOptOut(); Debug.WriteLine("Read time {0} ms", sw.ElapsedMilliseconds); }
public EventStoreSettings Build( DbConnections connections, IPublisherFactory publisherFactory, IEventSerializer eventSerializer, ISnapshotSerializer snapshotSerializer) { if (snapshotSerializer == null) { throw new ArgumentNullException(nameof(snapshotSerializer)); } var tempSettings = Build(connections, publisherFactory, eventSerializer); var snapshotsSettings = new SnapshotsSettings(_thresholdResolver, snapshotSerializer); return(new EventStoreSettings( tempSettings.Store, tempSettings.AggregateFactories, snapshotsSettings)); }
public void Snapshot(IAggregateEx aggregate, String bucket, Int32 numberOfEventsSaved) { if (SnapshotsSettings.HasOptedOut(aggregate.GetType())) { return; } var memento = aggregate.GetSnapshot(); var snapshot = new Snapshot(bucket, aggregate.Id.AsString(), aggregate.Version, memento); if (_cacheEnabled) { _cache.Set(aggregate.Id.AsString(), snapshot, _standardCachePolicy); } if (_snapshotPersistenceStrategy.ShouldSnapshot(aggregate, numberOfEventsSaved)) { _persister.Persist(snapshot, aggregate.GetType().FullName); } }
private static IServiceCollection AddSnapshotStore( this IServiceCollection services, SnapshotsSettings settings, DbConnections connections, IEventStoreContext context, ILoggerFactory loggerFactory) { if (settings == null) { return(services); } if (settings.Serializer == null) { throw new ArgumentException("Snapshot serializer not specified."); } if (settings.TriggerResolver == null) { throw new ArgumentException("ThresholdResolver not specified."); } var snapshotStore = new SnapshotStore( connections, context, settings.Serializer); var loggingStore = new LoggingSnapshotStore( snapshotStore, loggerFactory.CreateLogger <LoggingSnapshotStore>()); services.AddSingleton <ISnapshotStore>(loggingStore); services.AddSingleton(settings.Serializer); services.AddSingleton(settings.TriggerResolver); return(services); }