SetCurrent() public method

Sets the new scope as current using existing current as input.
public SetCurrent ( SetCurrentScopeHandler setCurrentScope ) : IScope
setCurrentScope SetCurrentScopeHandler Delegate to get new scope.
return IScope
示例#1
0
        /// <inheritdoc />
        public void OnBeginRequest(object sender, EventArgs _)
        {
            var httpContext  = ((HttpApplication)sender).Context;
            var scopeContext = new HttpContextScopeContext(() => httpContext.Items);

            scopeContext.SetCurrent(SetOrKeepCurrentRequestScope);
        }
示例#2
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();
                }
            };
        }
示例#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
        /// <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();
                }
            };
        }