Exemple #1
0
        public TAggregate GetById <TAggregate>(string id) where TAggregate : AggregateBase, new()
        {
            var json   = File.ReadAllText(MakeAggregateStreamFileName(id));
            var stream = (EventStream)JsonConvert.DeserializeObject(json, new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.All
            });

            return(AggregateBase.Load <TAggregate>(stream));
        }
Exemple #2
0
        public void Save(AggregateBase aggregate)
        {
            var stream = new EventStream();

            aggregate.Save(stream);
            var json = JsonConvert.SerializeObject(stream, new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.All,
                Formatting       = Formatting.Indented
            });

            File.WriteAllText(MakeAggregateStreamFileName(aggregate.Id), json);

            Dispatch(stream);
        }