Exemple #1
0
        public void WithSimpleInjector()
        {
            try
            {
                var container = new Container();
                container.RegisterNSagaComponents();
                container.UseSagaRepository <AzureTablesSagaRepository>();

                // You need Azure Storage emulator running to run this
                var connectionString = "UseDevelopmentStorage=true";
                container.Register <ITableClientFactory>(() => new TableClientFactory(connectionString), Lifestyle.Singleton);

                sagaMediator = container.GetInstance <ISagaMediator>();

                var correlationId = Guid.NewGuid();
                var initMessage   = new PersonalDetailsVerification(correlationId)
                {
                    FirstName = "James",
                    LastName  = "Bond",
                };

                sagaMediator.Consume(initMessage);
            }
            catch (Exception)
            {
                Console.WriteLine("Quite likely you don't have Azure Storage Emulator running, so this sample can't be executed");
            }
        }
Exemple #2
0
        public void Run()
        {
            try
            {
                // You need Azure Storage emulator running to run this
                var connectionString = "UseDevelopmentStorage=true";
                var builder          = Wireup.UseInternalContainer()
                                       .UseRepository <AzureTablesSagaRepository>()
                                       .Register(typeof(ITableClientFactory), new TableClientFactory(connectionString));

                sagaMediator = builder.ResolveMediator();

                var correlationId = Guid.NewGuid();
                var initMessage   = new PersonalDetailsVerification(correlationId)
                {
                    FirstName = "James",
                    LastName  = "Bond",
                };

                sagaMediator.Consume(initMessage);
            }
            catch (Exception)
            {
                Console.WriteLine("Quite likely you don't have Azure Storage Emulator running, so this sample can't be executed");
            }
        }
        public void RunSample()
        {
            var container = new Container();

            container.RegisterNSagaComponents();

            var mediator = container.GetInstance <ISagaMediator>();

            var correlationId = Guid.NewGuid();
            var initMessage   = new PersonalDetailsVerification(correlationId);

            mediator.Consume(initMessage);
        }
Exemple #4
0
        private static void StartSaga(Guid correlationId)
        {
            var initialMessage = new PersonalDetailsVerification(correlationId)
            {
                DateOfBirth   = new DateTime(1920, 11, 11),
                FirstName     = "James",
                LastName      = "Bond",
                HomePostcode  = "MI6 HQ",
                PayrollNumber = "007",
            };

            var result = _sagaMediator.Consume(initialMessage);

            if (!result.IsSuccessful)
            {
                Console.WriteLine(result.ToString());
            }
        }
Exemple #5
0
        public OperationResult Initiate(PersonalDetailsVerification message)
        {
            if (message.FirstName != "James" || message.LastName != "Bond")
            {
                return(new OperationResult("This Saga only works for James Bond"));
            }

            var person = new Person()
            {
                FirstName       = message.FirstName,
                LastName        = message.LastName,
                ReferenceNumber = message.PayrollNumber,
                Postcode        = message.HomePostcode,
                PrivateEmail    = "*****@*****.**",
                WorkEmail       = "*****@*****.**",
                WorkMobile      = "07007007007",
                PrivateMobile   = "07123456789",
            };

            SagaData.Person = person;
            Console.WriteLine($"Saga initiated. Person in question is {person.FullName}");
            return(new OperationResult().AddPayload(person));
        }