Ejemplo n.º 1
0
        public static MiddlewaresChain BuildFullChain(IServiceProvider serviceProvider, params ExecuteSagaDelegate[] executeDelegates)
        {
            MiddlewaresChain actions = new MiddlewaresChain();

            foreach (var item in beforeSetMiddlewares)
            {
                actions.Add(new NextMiddleware(serviceProvider, item, null));
            }

            foreach (var executeDelegate in executeDelegates)
            {
                actions.Add(new NextMiddleware(serviceProvider, null, executeDelegate));
            }

            foreach (var item in afterGetMiddlewares)
            {
                actions.Add(new NextMiddleware(serviceProvider, item, null));
            }

            for (var i = 0; i < actions.Count - 1; i++)
            {
                var action     = actions[i];
                var nextAction = actions[i + 1];
                action.Next = nextAction;
            }

            return(actions);
        }
Ejemplo n.º 2
0
        public static async Task ExecuteAfterRequestCallbacks(IServiceProvider serviceProvider, ISaga saga, Exception ex)
        {
            var scopeFactory = serviceProvider.GetRequiredService <IServiceScopeFactory>();

            using var scope = scopeFactory.CreateScope();

            using var beforeStartCallbackExecuter = new AfterRequestCallbackExecuter(
                      afterRequestCallbacks, scope.ServiceProvider, ex);

            MiddlewaresChain middlewaresChain = Middlewares.BuildSimpleChain(
                scope.ServiceProvider,
                beforeStartCallbackExecuter.Execute);

            await Middlewares.ExecuteChain(
                middlewaresChain,
                saga, null, null);
        }