Stores current scope in HttpContext.Items.
Stateless context, so could be created multiple times and used from different places without side-effects.
Inheritance: IScopeContext, IDisposable
Ejemplo n.º 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();
                }
            };
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public void OnBeginRequest(object sender, EventArgs _)
        {
            var httpContext  = ((HttpApplication)sender).Context;
            var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

            scopeContext.SetCurrent(SetOrKeepCurrentRequestScope);
        }
Ejemplo n.º 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();
            };
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
                }
            };
        }
Ejemplo n.º 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();
            };
        }
Ejemplo n.º 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();
            };
        }