Skip to content

Commit

Permalink
#3 Moving Core.Web
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Gerbenis committed Sep 18, 2015
1 parent 4194707 commit 59cf1a0
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 226 deletions.
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();
// }
// }
// }
// }
// }
//}
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);
// };
// }
// }
//}
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;

using BetterModules.Core.Dependencies;
using BetterModules.Core.Exceptions;
using BetterModules.Core.Web.Dependencies;
using BetterModules.Core.Web.Environment.Application;

using Common.Logging;

[assembly: WebApplicationPreStartAttribute(typeof(WebApplicationEntryPoint), "PreApplicationStart", Order = 100)]

namespace BetterModules.Core.Web.Environment.Application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
using System.Linq;
using System.Reflection;
using System.Security;
using System.Web;
using System.Web.Compilation;
using System.Web.Hosting;
using BetterModules.Core.Web.Environment.Application;
using BetterModules.Core.Web.Extensions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Reflection;
using System.Web.Compilation;
using BetterModules.Core.Environment.Assemblies;
using BetterModules.Core.Environment.FileSystem;
using BetterModules.Core.Modules.Registration;
using BetterModules.Core.Web.Web.EmbeddedResources;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Logging;
using IAssemblyLoader = BetterModules.Core.Environment.Assemblies.IAssemblyLoader;

namespace BetterModules.Core.Web.Environment.Assemblies
{
Expand All @@ -22,8 +24,9 @@ public class DefaultWebAssemblyManager : DefaultAssemblyManager
/// <param name="embeddedResourcesProvider">The embedded resources provider.</param>
/// <param name="assemblyLoader">The assembly loader.</param>
public DefaultWebAssemblyManager(IWorkingDirectory workingDirectory, IModulesRegistration modulesRegistration,
IEmbeddedResourcesProvider embeddedResourcesProvider, IAssemblyLoader assemblyLoader)
: base(workingDirectory, modulesRegistration, assemblyLoader)
IEmbeddedResourcesProvider embeddedResourcesProvider, IAssemblyLoader assemblyLoader,
ILibraryManager libraryManager, ILoggerFactory loggerFactory)
: base(workingDirectory, modulesRegistration, assemblyLoader, libraryManager, loggerFactory)
{
this.embeddedResourcesProvider = embeddedResourcesProvider;
}
Expand All @@ -36,7 +39,8 @@ public override void AddUploadedModule(Assembly assembly)
{
base.AddUploadedModule(assembly);

BuildManager.AddReferencedAssembly(assembly);
//TODO: Check how to add referenced assembly (if we need to do it at all)
//BuildManager.AddReferencedAssembly(assembly);
embeddedResourcesProvider.AddEmbeddedResourcesFrom(assembly);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Hosting;
using System.Web.Mvc;
using BetterModules.Core.Exceptions;
using BetterModules.Core.Web.Exceptions.Host;
using Common.Logging;
using RazorGenerator.Mvc;

namespace BetterModules.Core.Web.Environment.Host
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Web;
using System.Web.Routing;
using Autofac;
using BetterModules.Core.Dependencies;
using BetterModules.Core.Web.Environment.Application;
using BetterModules.Core.Web.Environment.Host;
using BetterModules.Core.Web.Modules.Registration;
Expand Down
Loading

0 comments on commit 59cf1a0

Please sign in to comment.