Esempio n. 1
0
        IPublishScopeContext <T> IPublishScopeProvider.GetScope <T>(PublishContext <T> context)
            where T : class
        {
            if (context.TryGetPayload <ILifetimeScope>(out _))
            {
                return(new ExistingPublishScopeContext <T>(context));
            }

            var parentLifetimeScope = _scopeProvider.GetLifetimeScope(context);

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

            try
            {
                PublishContext <T> publishContext = lifetimeScope.GetPublishScope(context);

                return(new CreatedPublishScopeContext <ILifetimeScope, T>(lifetimeScope, publishContext));
            }
            catch
            {
                lifetimeScope.Dispose();

                throw;
            }
        }
Esempio n. 2
0
        public IPublishScopeContext <T> GetScope <T>(PublishContext <T> context)
            where T : class
        {
            if (context.TryGetPayload <IServiceScope>(out _))
            {
                return(new ExistingPublishScopeContext <T>(context));
            }

            if (!context.TryGetPayload(out IServiceProvider serviceProvider))
            {
                serviceProvider = _serviceProvider;
            }

            var serviceScope = serviceProvider.CreateScope();

            try
            {
                var publishContext = new PublishContextScope <T>(context, serviceScope, serviceScope.ServiceProvider);

                return(new CreatedPublishScopeContext <IServiceScope, T>(serviceScope, publishContext));
            }
            catch
            {
                serviceScope.Dispose();

                throw;
            }
        }
Esempio n. 3
0
        public async Task Should_contains_scope_on_publish()
        {
            await Bus.Publish(new SimpleMessageClass("test"));

            PublishContext published = await _taskCompletionSource.Task;

            Assert.IsTrue(published.TryGetPayload <TScope>(out _));
        }
        public Task Send(PublishContext <T> context, IPipe <PublishContext <T> > next)
        {
            if (context.TryGetPayload <ApplicationInsightsPayload>(out _))
            {
                return(next.Send(context));
            }

            context.GetOrAddPayload(() => new ApplicationInsightsPayload());

            return(SendWithTelemetry(context, next));
        }
        public IPublishScopeContext <T> GetScope <T>(PublishContext <T> context)
            where T : class
        {
            if (context.TryGetPayload <INestedContainer>(out _))
            {
                return(new ExistingPublishScopeContext <T>(context));
            }

            var nestedContainer = _container.GetNestedContainer(context);

            try
            {
                var publishContext = new PublishContextScope <T>(context, nestedContainer);

                return(new CreatedPublishScopeContext <INestedContainer, T>(nestedContainer, publishContext));
            }
            catch
            {
                nestedContainer.Dispose();
                throw;
            }
        }
Esempio n. 6
0
        public IPublishScopeContext <T> GetScope <T>(PublishContext <T> context)
            where T : class
        {
            if (context.TryGetPayload <IKernel>(out _))
            {
                return(new ExistingPublishScopeContext <T>(context));
            }

            var scope = _kernel.CreateNewMessageScope(context);

            try
            {
                var publishContext = new PublishContextScope <T>(context, _kernel);

                return(new CreatedPublishScopeContext <IDisposable, T>(scope, publishContext));
            }
            catch
            {
                scope?.Dispose();
                throw;
            }
        }
Esempio n. 7
0
        public IPublishScopeContext <T> GetScope <T>(PublishContext <T> context)
            where T : class
        {
            if (context.TryGetPayload <Scope>(out _))
            {
                return(new ExistingPublishScopeContext <T>(context));
            }

            var scope = AsyncScopedLifestyle.BeginScope(_container);

            try
            {
                var publishContext = new PublishContextScope <T>(context, scope, scope.Container);

                return(new CreatedPublishScopeContext <Scope, T>(scope, publishContext));
            }
            catch
            {
                scope.Dispose();

                throw;
            }
        }