-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lukas Gerbenis
committed
Sep 18, 2015
1 parent
4194707
commit 59cf1a0
Showing
18 changed files
with
187 additions
and
226 deletions.
There are no files selected for viewing
183 changes: 90 additions & 93 deletions
183
vNext/src/BetterModules.Core.Web/Dependencies/PerWebRequestContainerProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,101 @@ | ||
using System; | ||
using System.Web; | ||
using Autofac; | ||
using BetterModules.Core.Dependencies; | ||
using BetterModules.Core.Web.Web; | ||
//using System; | ||
//using BetterModules.Core.Web.Web; | ||
|
||
namespace BetterModules.Core.Web.Dependencies | ||
{ | ||
/// <summary> | ||
/// Service locator to support per web request life time manager. | ||
/// </summary> | ||
public class PerWebRequestContainerProvider | ||
{ | ||
/// <summary> | ||
/// Marker key. | ||
/// </summary> | ||
private static readonly object PerWebRequestContainerKey = new object(); | ||
//namespace BetterModules.Core.Web.Dependencies | ||
//{ | ||
// /// <summary> | ||
// /// Service locator to support per web request life time manager. | ||
// /// </summary> | ||
// public class PerWebRequestContainerProvider | ||
// { | ||
// /// <summary> | ||
// /// Marker key. | ||
// /// </summary> | ||
// private static readonly object PerWebRequestContainerKey = new object(); | ||
|
||
/// <summary> | ||
/// The HTTP context accessor. | ||
/// </summary> | ||
private readonly IHttpContextAccessor httpContextAccessor; | ||
// /// <summary> | ||
// /// The HTTP context accessor. | ||
// /// </summary> | ||
// private readonly IHttpContextAccessor httpContextAccessor; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PerWebRequestContainerProvider" /> class. | ||
/// </summary> | ||
/// <param name="httpContextAccessor">The HTTP context accessor.</param> | ||
public PerWebRequestContainerProvider(IHttpContextAccessor httpContextAccessor) | ||
{ | ||
this.httpContextAccessor = httpContextAccessor; | ||
} | ||
// /// <summary> | ||
// /// Initializes a new instance of the <see cref="PerWebRequestContainerProvider" /> class. | ||
// /// </summary> | ||
// /// <param name="httpContextAccessor">The HTTP context accessor.</param> | ||
// public PerWebRequestContainerProvider(IHttpContextAccessor httpContextAccessor) | ||
// { | ||
// this.httpContextAccessor = httpContextAccessor; | ||
// } | ||
|
||
/// <summary> | ||
/// Gets the child container. | ||
/// </summary> | ||
/// <value> | ||
/// The child container. | ||
/// </value> | ||
public ILifetimeScope CurrentScope | ||
{ | ||
get | ||
{ | ||
var httpContext = httpContextAccessor.GetCurrent(); | ||
// /// <summary> | ||
// /// Gets the child container. | ||
// /// </summary> | ||
// /// <value> | ||
// /// The child container. | ||
// /// </value> | ||
// public ILifetimeScope CurrentScope | ||
// { | ||
// get | ||
// { | ||
// var httpContext = httpContextAccessor.GetCurrent(); | ||
|
||
ILifetimeScope requestContainer = httpContext.Items[PerWebRequestContainerKey] as ILifetimeScope; | ||
// ILifetimeScope requestContainer = httpContext.Items[PerWebRequestContainerKey] as ILifetimeScope; | ||
|
||
if (requestContainer == null) | ||
{ | ||
httpContext.Items[PerWebRequestContainerKey] = requestContainer = ContextScopeProvider.CreateChildContainer(); | ||
} | ||
// if (requestContainer == null) | ||
// { | ||
// httpContext.Items[PerWebRequestContainerKey] = requestContainer = ContextScopeProvider.CreateChildContainer(); | ||
// } | ||
|
||
return requestContainer; | ||
} | ||
} | ||
// return requestContainer; | ||
// } | ||
// } | ||
|
||
/// <summary> | ||
/// Gets the lifetime scope. | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <returns>The child container.</returns> | ||
public static ILifetimeScope GetLifetimeScope(HttpContextBase context) | ||
{ | ||
return context.Items[PerWebRequestContainerKey] as ILifetimeScope; | ||
} | ||
// /// <summary> | ||
// /// Gets the lifetime scope. | ||
// /// </summary> | ||
// /// <param name="context">The context.</param> | ||
// /// <returns>The child container.</returns> | ||
// public static ILifetimeScope GetLifetimeScope(HttpContextBase context) | ||
// { | ||
// return context.Items[PerWebRequestContainerKey] as ILifetimeScope; | ||
// } | ||
|
||
/// <summary> | ||
/// Disposes the managed resources. | ||
/// </summary> | ||
protected void DisposeManagedResources() | ||
{ | ||
var httpContext = httpContextAccessor.GetCurrent(); | ||
if (httpContext != null) | ||
{ | ||
var requestContainer = httpContext.Items[PerWebRequestContainerKey] as ILifetimeScope; | ||
// /// <summary> | ||
// /// Disposes the managed resources. | ||
// /// </summary> | ||
// protected void DisposeManagedResources() | ||
// { | ||
// var httpContext = httpContextAccessor.GetCurrent(); | ||
// if (httpContext != null) | ||
// { | ||
// var requestContainer = httpContext.Items[PerWebRequestContainerKey] as ILifetimeScope; | ||
|
||
if (requestContainer != null) | ||
{ | ||
requestContainer.Dispose(); | ||
} | ||
} | ||
} | ||
// if (requestContainer != null) | ||
// { | ||
// requestContainer.Dispose(); | ||
// } | ||
// } | ||
// } | ||
|
||
/// <summary> | ||
/// Disposes the current scope. | ||
/// </summary> | ||
/// <param name="sender">The sender.</param> | ||
/// <param name="args">The <see cref="EventArgs"/> instance containing the event data.</param> | ||
internal static void DisposeCurrentScope(object sender, EventArgs args) | ||
{ | ||
var httpApplication = sender as HttpApplication; | ||
if (httpApplication != null) | ||
{ | ||
if (httpApplication.Context != null) | ||
{ | ||
var requestContainer = httpApplication.Context.Items[PerWebRequestContainerKey] as ILifetimeScope; | ||
if (requestContainer != null) | ||
{ | ||
requestContainer.Dispose(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// /// <summary> | ||
// /// Disposes the current scope. | ||
// /// </summary> | ||
// /// <param name="sender">The sender.</param> | ||
// /// <param name="args">The <see cref="EventArgs"/> instance containing the event data.</param> | ||
// internal static void DisposeCurrentScope(object sender, EventArgs args) | ||
// { | ||
// var httpApplication = sender as HttpApplication; | ||
// if (httpApplication != null) | ||
// { | ||
// if (httpApplication.Context != null) | ||
// { | ||
// var requestContainer = httpApplication.Context.Items[PerWebRequestContainerKey] as ILifetimeScope; | ||
// if (requestContainer != null) | ||
// { | ||
// requestContainer.Dispose(); | ||
// } | ||
// } | ||
// } | ||
// } | ||
// } | ||
//} |
86 changes: 43 additions & 43 deletions
86
vNext/src/BetterModules.Core.Web/Dependencies/PerWebRequestLifetimeModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
using System.Web; | ||
using Microsoft.Web.Infrastructure.DynamicModuleHelper; | ||
//using System.Web; | ||
//using Microsoft.Web.Infrastructure.DynamicModuleHelper; | ||
|
||
namespace BetterModules.Core.Web.Dependencies | ||
{ | ||
/// <summary> | ||
/// Per web request lifetime http module. | ||
/// </summary> | ||
public class PerWebRequestLifetimeModule : IHttpModule | ||
{ | ||
/// <summary> | ||
/// Indicates if module is starting. | ||
/// </summary> | ||
private static bool isStarting; | ||
//namespace BetterModules.Core.Web.Dependencies | ||
//{ | ||
// /// <summary> | ||
// /// Per web request lifetime http module. | ||
// /// </summary> | ||
// public class PerWebRequestLifetimeModule : IHttpModule | ||
// { | ||
// /// <summary> | ||
// /// Indicates if module is starting. | ||
// /// </summary> | ||
// private static bool isStarting; | ||
|
||
/// <summary> | ||
/// Dynamic the module registration. | ||
/// </summary> | ||
public static void DynamicModuleRegistration() | ||
{ | ||
if (!isStarting) | ||
{ | ||
isStarting = true; | ||
DynamicModuleUtility.RegisterModule(typeof(PerWebRequestLifetimeModule)); | ||
} | ||
} | ||
// /// <summary> | ||
// /// Dynamic the module registration. | ||
// /// </summary> | ||
// public static void DynamicModuleRegistration() | ||
// { | ||
// if (!isStarting) | ||
// { | ||
// isStarting = true; | ||
// DynamicModuleUtility.RegisterModule(typeof(PerWebRequestLifetimeModule)); | ||
// } | ||
// } | ||
|
||
/// <summary> | ||
/// Disposes of the resources (other than memory) used by the module that implements <see cref="T:System.Web.IHttpModule" />. | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
} | ||
// /// <summary> | ||
// /// Disposes of the resources (other than memory) used by the module that implements <see cref="T:System.Web.IHttpModule" />. | ||
// /// </summary> | ||
// public void 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> | ||
public void Init(HttpApplication context) | ||
{ | ||
context.EndRequest += (sender, e) => | ||
{ | ||
PerWebRequestContainerProvider.DisposeCurrentScope(sender, e); | ||
}; | ||
} | ||
} | ||
} | ||
// /// <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> | ||
// public void Init(HttpApplication context) | ||
// { | ||
// context.EndRequest += (sender, e) => | ||
// { | ||
// PerWebRequestContainerProvider.DisposeCurrentScope(sender, e); | ||
// }; | ||
// } | ||
// } | ||
//} |
5 changes: 0 additions & 5 deletions
5
vNext/src/BetterModules.Core.Web/Environment/Application/WebApplicationEntryPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
vNext/src/BetterModules.Core.Web/Environment/Host/DefaultWebApplicationAutoHost.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
vNext/src/BetterModules.Core.Web/Environment/Host/UtilityHost.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.