Exemplo n.º 1
0
        public ISagaQueryScopeContext <TSaga, T> GetQueryScope <T>(SagaQueryConsumeContext <TSaga, T> context)
            where T : class
        {
            if (context.TryGetPayload <IContainer>(out _))
            {
                return(new ExistingSagaQueryScopeContext <TSaga, T>(context));
            }

            var container = _container.GetNestedContainer(context);

            try
            {
                var proxy             = new SagaQueryConsumeContextProxy <TSaga, T>(context, new PayloadCacheScope(context), context.Query);
                var consumerContainer = container;

                proxy.GetOrAddPayload(() => consumerContainer);
                foreach (Action <ConsumeContext> scopeAction in _scopeActions)
                {
                    scopeAction(proxy);
                }

                return(new CreatedSagaQueryScopeContext <IContainer, TSaga, T>(consumerContainer, proxy));
            }
            catch
            {
                container.Dispose();
                throw;
            }
        }
Exemplo n.º 2
0
        ISagaQueryScopeContext <TSaga, T> ISagaScopeProvider <TSaga> .GetQueryScope <T>(SagaQueryConsumeContext <TSaga, T> context)
        {
            if (context.TryGetPayload <ILifetimeScope>(out _))
            {
                return(new ExistingSagaQueryScopeContext <TSaga, T>(context));
            }

            var parentLifetimeScope = _scopeProvider.GetLifetimeScope(context);

            var lifetimeScope = parentLifetimeScope.BeginLifetimeScope(_name, builder =>
            {
                builder.ConfigureScope(context);
                _configureScope?.Invoke(builder, context);
            });

            try
            {
                var proxy = new SagaQueryConsumeContextProxy <TSaga, T>(context, new PayloadCacheScope(context), context.Query);
                proxy.UpdatePayload(lifetimeScope);

                foreach (Action <ConsumeContext> scopeAction in _scopeActions)
                {
                    scopeAction(proxy);
                }

                return(new CreatedSagaQueryScopeContext <ILifetimeScope, TSaga, T>(lifetimeScope, proxy));
            }
            catch
            {
                lifetimeScope.Dispose();

                throw;
            }
        }
        public ISagaQueryScopeContext <TSaga, T> GetQueryScope <T>(SagaQueryConsumeContext <TSaga, T> context) where T : class
        {
            if (context.TryGetPayload <IKernel>(out _))
            {
                return(new ExistingSagaQueryScopeContext <TSaga, T>(context));
            }

            var scope = _container.BeginScope();

            _container.Register(Component.For <ConsumeContext, ConsumeContext <T> >().Instance(context));

            try
            {
                var proxy = new SagaQueryConsumeContextProxy <TSaga, T>(context, new PayloadCacheScope(context), context.Query);

                var consumerContainer = _container;
                proxy.GetOrAddPayload(() => consumerContainer);
                foreach (Action <ConsumeContext> scopeAction in _scopeActions)
                {
                    scopeAction(proxy);
                }

                return(new CreatedSagaQueryScopeContext <IDisposable, TSaga, T>(scope, proxy));
            }
            catch
            {
                scope.Dispose();

                throw;
            }
        }