/// <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(); } }; }
/// <inheritdoc /> public void OnBeginRequest(object sender, EventArgs _) { var httpContext = ((HttpApplication)sender).Context; var scopeContext = new HttpContextScopeContext(() => httpContext.Items); scopeContext.SetCurrent(SetOrKeepCurrentRequestScope); }
/// <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(); }; }
/// <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(); } }
/// <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(); } }; }
/// <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(); }; }
/// <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(); }; }