public void SaveSnapshot(Snapshot.Snapshot snapshot)
        {
            var connection = GetEventStoreConnection();

            connection.ConnectAsync().Wait();

            JsonSerializerSettings serializerSettings = new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.All
            };

            var snapshotyEvent = new EventData(snapshot.Id, @snapshot.GetType().ToString(), false,
                                               Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(snapshot, serializerSettings)),
                                               Encoding.UTF8.GetBytes(snapshot.GetType().ToString()));

            connection.AppendToStreamAsync($"{eventNamePrefix}-{snapshot.AggregateId}",
                                           ExpectedVersion.Any, snapshotyEvent).Wait();

            connection.Close();
        }
Esempio n. 2
0
 /// <summary>
 /// Use this method when you are trying to load a base type, which in it self does not implement
 /// the <see cref="ISnapshottable{T}" /> interface, but  you have a snapshot indicating
 /// that you need to instantiate child type instead.
 /// </summary>
 /// <typeparam name="T">The aggregate type</typeparam>
 /// <param name="snapshot">The snapshot</param>
 /// <returns>A subclass instance as <typeparam name="T"></typeparam></returns>
 public T CreateAggregate <T>(Snapshot.Snapshot snapshot) where T : class, IAggregateRoot
 {
     return((T)_resolver.Resolve(_snapshotToTypeMap[snapshot.GetType()]));
 }