Esempio n. 1
0
        public override Stream Process(Stream requestStream)
        {
            ServiceScopeWrapper serviceScope = this.RootContainer.CreateServiceScope();

            this.RequestContainer = serviceScope.ServiceProvider;

            try
            {
                RequestHandler handler = this.DispatchHandler();

                if (this.PreferenceContext.RespondAsync)
                {
                    return(handler.ProcessAsynchronously(requestStream));
                }
                return(handler.Process(requestStream));
            }
            catch (Exception e)
            {
                ErrorHandler handler = new ErrorHandler(this, e);
                return(handler.Process(null));
            }
            finally
            {
                serviceScope.Dispose();
            }
        }
        public IDisposable BeginScope()
        {
            IServiceProvider provider;

            if (this.scopes.Value == null)
            {
                this.scopes.Value = new Stack <ServiceScopeWrapper>();
                provider          = this.serviceProvider;
            }
            else
            {
                provider = this.scopes.Value.Count > 0 ? this.scopes.Value.Peek().Scope.ServiceProvider : this.serviceProvider;
            }

            var scope = new ServiceScopeWrapper(provider.CreateScope(), this);

            try
            {
                this.scopes.Value.Push(scope);
                return(scope);
            }
            catch
            {
                scope.Dispose();
                throw;
            }
        }
        public IServiceScope CreateScope()
        {
            var scope = new ServiceScopeWrapper(this);

            // A new scope can be only used on a non released shell.
            if (!_released)
            {
                return(scope);
            }

            (scope as ServiceScopeWrapper).Dispose();

            return(null);
        }