示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            var coordinator = app.ApplicationServices.GetService <ISagaCoordinator>();

            var context = SagaContext
                          .Create()
                          .WithSagaId(SagaId.NewSagaId())
                          .WithOriginator("Test")
                          .WithMetadata("key", "lulz")
                          .Build();

            var context2 = SagaContext
                           .Create()
                           .WithSagaId(SagaId.NewSagaId())
                           .WithOriginator("Test")
                           .WithMetadata("key", "lulz")
                           .Build();

            coordinator.ProcessAsync(new Message1 {
                Text = "This message will be used one day..."
            }, context);

            coordinator.ProcessAsync(new Message2 {
                Text = "But this one will be printed first! (We compensate from the end to beggining of the log)"
            },
                                     onCompleted: (m, ctx) =>
            {
                Console.WriteLine("My work is done");
                return(Task.CompletedTask);
            },
                                     context: context);

            Console.ReadLine();
        }
示例#2
0
 public async Task Handle(OrderCreated notification, CancellationToken cancellationToken)
 {
     // DO WORK HERE
     IEnumerable <ISagaContextMetadata> metadata = new List <ISagaContextMetadata>();
     await _coordinator.ProcessAsync(notification,
                                     SagaContext.Create((SagaId)notification.OrderId.ToString(), notification.GetType().Name, metadata));
 }
示例#3
0
        public async Task Handle(OrderCreated notification, CancellationToken cancellationToken)
        {
            IEnumerable <ISagaContextMetadata> metadata = new List <ISagaContextMetadata>();
            await _coordinator.ProcessAsync(notification,
                                            SagaContext.Create((SagaId)notification.OrderId.ToString(), notification.GetType().Name, metadata));

            // once every thing is processed in the handler, commit changes to DB.
            // This can be moved else where depending on the user needs.
            await SagaUnitOfWork.CommitAsync();
        }