Stores current scope in HttpContext.Items.
Stateless context, so could be created multiple times and used from different places without side-effects.
상속: IScopeContext, IDisposable
예제 #1
0
        /// <summary>Initializes a plugin and prepares it to handle requests. </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpApplication"/> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application </param>
        void IHttpModule.Init(HttpApplication context)
        {
            var scopeName = Reuse.WebRequestScopeName;

            context.BeginRequest += (sender, _) =>
            {
                var httpContext  = (sender as HttpApplication).ThrowIfNull().Context;
                var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

                // If current scope does not have WebRequestScopeName then create new scope with this name,
                // otherwise - use current.
                scopeContext.SetCurrent(current =>
                                        current != null && scopeName.Equals(current.Name) ? current : new Scope(current, scopeName));
            };

            context.EndRequest += (sender, _) =>
            {
                var httpContext  = (sender as HttpApplication).ThrowIfNull().Context;
                var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

                var currentScope = scopeContext.GetCurrentOrDefault();
                if (currentScope != null && scopeName.Equals(currentScope.Name))
                {
                    currentScope.Dispose();
                }
            };
        }
예제 #2
0
        /// <inheritdoc />
        public void OnBeginRequest(object sender, EventArgs _)
        {
            var httpContext  = ((HttpApplication)sender).Context;
            var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

            scopeContext.SetCurrent(SetOrKeepCurrentRequestScope);
        }
예제 #3
0
        /// <summary>Initializes a plugin and prepares it to handle requests. </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpApplication"/> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application </param>
        void IHttpModule.Init(HttpApplication context)
        {
            var scopeName = Reuse.WebRequestScopeName;

            context.BeginRequest += (sender, _) =>
            {
                var httpContext = (sender as HttpApplication).ThrowIfNull().Context;
                var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

                // If current scope does not have WebRequestScopeName then create new scope with this name,
                // otherwise - use current.
                scopeContext.SetCurrent(current =>
                    current != null && scopeName.Equals(current.Name) ? current : new Scope(current, scopeName));
            };

            context.EndRequest += (sender, _) =>
            {
                var httpContext = (sender as HttpApplication).ThrowIfNull().Context;
                var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

                var currentScope = scopeContext.GetCurrentOrDefault();
                if (currentScope != null && scopeName.Equals(currentScope.Name))
                    currentScope.Dispose();
            };
        }
예제 #4
0
        /// <inheritdoc />
        public void OnEndRequest(object sender, EventArgs _)
        {
            var httpContext  = ((HttpApplication)sender).Context;
            var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

            var currentScope = scopeContext.GetCurrentOrDefault();

            if (currentScope != null && Reuse.WebRequestScopeName.Equals(currentScope.Name))
            {
                currentScope.Dispose();
            }
        }
예제 #5
0
        /// <summary>Initializes a module and prepares it to handle requests. </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpApplication"/> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application </param>
        void IHttpModule.Init(HttpApplication context)
        {
            context.BeginRequest += (sender, _) =>
            {
                var httpContext  = ((HttpApplication)sender).Context;
                var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

                scopeContext.SetCurrent(SetOrKeepCurrentRequestScope);
            };

            context.EndRequest += (sender, _) =>
            {
                var httpContext  = ((HttpApplication)sender).Context;
                var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

                var currentScope = scopeContext.GetCurrentOrDefault();
                if (currentScope != null && Reuse.WebRequestScopeName.Equals(currentScope.Name))
                {
                    currentScope.Dispose();
                }
            };
        }
예제 #6
0
        /// <summary>Initializes a module and prepares it to handle requests. </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpApplication"/> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application </param>
        void IHttpModule.Init(HttpApplication context)
        {
            context.BeginRequest += (sender, _) =>
            {
                var httpContext  = (sender as HttpApplication).ThrowIfNull().Context;
                var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

                scopeContext.OpenScope()
                .ThrowIf(s => s.Parent != null, Error.ROOT_SCOPE_IS_ALREADY_OPENED);
            };

            context.EndRequest += (sender, _) =>
            {
                var httpContext  = (sender as HttpApplication).ThrowIfNull().Context;
                var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

                var scope = scopeContext.GetCurrentOrDefault()
                            .ThrowIfNull(Error.NO_OPENED_SCOPE_TO_DISPOSE)
                            .ThrowIf(s => s.Parent != null, Error.NOT_THE_ROOT_OPENED_SCOPE);

                scope.Dispose();
            };
        }
예제 #7
0
        /// <summary>Initializes a module and prepares it to handle requests. </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpApplication"/> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application </param>
        void IHttpModule.Init(HttpApplication context)
        {
            context.BeginRequest += (sender, _) =>
            {
                var httpContext = (sender as HttpApplication).ThrowIfNull().Context;
                var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

                //scopeContext.OpenScope();
                //.ThrowIf(s => s.Parent != null, Error.ROOT_SCOPE_IS_ALREADY_OPENED);
            };

            context.EndRequest += (sender, _) =>
            {
                var httpContext = (sender as HttpApplication).ThrowIfNull().Context;
                var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

                var scope = scopeContext.GetCurrentOrDefault();
                //.ThrowIfNull(Erro.NO_OPENED_SCOPE_TO_DISPOSE)
                //.ThrowIf(s => s.Parent != null, Error.NOT_THE_ROOT_OPENED_SCOPE);

                scope.Dispose();
            };
        }