Пример #1
0
        static void Main(string[] args)
        {
            //Load dependency resolver
            var Resolver = new DependencyResolver();
            var rep      = Resolver.ResolveDependecy <IRepository <Note> >();

            #region "Create Note"

            //Create new note
            Note tmpNote = new Note("Test Note", "Event Sourcing System Demo", "Event Sourcing");

            Console.WriteLine("After Creation: This is version 1 of the AggregateRoot.");
            Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(tmpNote));
            Console.WriteLine();
            #endregion

            #region "Edit Note"

            Console.WriteLine("Doing some changes now...");
            Console.WriteLine("");

            //Do 10 x 5 events cycle to check snapshots too.
            for (int i = 0; i < 10; i++)
            {
                //Do some changes
                for (int x = 0; x < 5; x++)
                {
                    tmpNote.ChangeTitle($"Test Note 123 Event({tmpNote.CurrentVersion + 1})");
                    tmpNote.ChangeCategory($"Event Sourcing in .NET Example. Event({tmpNote.CurrentVersion + 1})");
                }

                Console.WriteLine($"Committing Changes Now For Cycle {i}");

                //Commit chnages to the repository
                rep.Save(tmpNote);
            }

            Console.WriteLine("");
            Console.WriteLine("After Committing Events:");
            Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(tmpNote));

            #endregion

            #region "Reload Note From Storage"

            //Load same note using the aggregate id
            //This will replay the saved events and construct a new note
            var tmpNoteToLoad = rep.GetById(tmpNote.Id);

            Console.WriteLine("");
            Console.WriteLine("After Replaying:");
            Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(tmpNoteToLoad));

            Console.WriteLine();
            Console.WriteLine("Press enter key to exit.");

            Console.ReadLine();

            #endregion
        }
Пример #2
0
        public void test_sequence_domain_event_process()
        {
            var processor = ObjectContainer.Resolve <IMessageProcessor <ProcessingDomainEventStreamMessage, DomainEventStreamMessage, bool> >();

            var note      = new Note(ObjectId.GenerateNewStringId(), "initial title");
            var aggregate = note as IAggregateRoot;
            var message1  = CreateMessage(aggregate);

            aggregate.AcceptChanges(1);
            note.ChangeTitle("title1");
            var message2 = CreateMessage(aggregate);

            aggregate.AcceptChanges(2);
            note.ChangeTitle("title2");
            var message3 = CreateMessage(aggregate);

            processor.Process(new ProcessingDomainEventStreamMessage(message1, new DomainEventStreamProcessContext(message1)));
            processor.Process(new ProcessingDomainEventStreamMessage(message3, new DomainEventStreamProcessContext(message3)));
            processor.Process(new ProcessingDomainEventStreamMessage(message2, new DomainEventStreamProcessContext(message2)));

            _waitHandle.WaitOne();
        }
Пример #3
0
        public void test_sequence_domain_event_process()
        {
            var processor = ObjectContainer.Resolve<IMessageProcessor<ProcessingDomainEventStreamMessage, DomainEventStreamMessage, bool>>();

            var note = new Note(ObjectId.GenerateNewStringId(), "initial title");
            var aggregate = note as IAggregateRoot;
            var message1 = CreateMessage(aggregate);

            aggregate.AcceptChanges(1);
            note.ChangeTitle("title1");
            var message2 = CreateMessage(aggregate);

            aggregate.AcceptChanges(2);
            note.ChangeTitle("title2");
            var message3 = CreateMessage(aggregate);

            processor.Process(new ProcessingDomainEventStreamMessage(message1, new DomainEventStreamProcessContext(message1)));
            processor.Process(new ProcessingDomainEventStreamMessage(message3, new DomainEventStreamProcessContext(message3)));
            processor.Process(new ProcessingDomainEventStreamMessage(message2, new DomainEventStreamProcessContext(message2)));

            _waitHandle.WaitOne();
        }