diff --git a/vNext/src/BetterModules.Core.Web/Dependencies/PerWebRequestContainerProvider.cs b/vNext/src/BetterModules.Core.Web/Dependencies/PerWebRequestContainerProvider.cs index 90f9d5b..eccf7c7 100644 --- a/vNext/src/BetterModules.Core.Web/Dependencies/PerWebRequestContainerProvider.cs +++ b/vNext/src/BetterModules.Core.Web/Dependencies/PerWebRequestContainerProvider.cs @@ -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 -{ - /// - /// Service locator to support per web request life time manager. - /// - public class PerWebRequestContainerProvider - { - /// - /// Marker key. - /// - private static readonly object PerWebRequestContainerKey = new object(); +//namespace BetterModules.Core.Web.Dependencies +//{ +// /// +// /// Service locator to support per web request life time manager. +// /// +// public class PerWebRequestContainerProvider +// { +// /// +// /// Marker key. +// /// +// private static readonly object PerWebRequestContainerKey = new object(); - /// - /// The HTTP context accessor. - /// - private readonly IHttpContextAccessor httpContextAccessor; +// /// +// /// The HTTP context accessor. +// /// +// private readonly IHttpContextAccessor httpContextAccessor; - /// - /// Initializes a new instance of the class. - /// - /// The HTTP context accessor. - public PerWebRequestContainerProvider(IHttpContextAccessor httpContextAccessor) - { - this.httpContextAccessor = httpContextAccessor; - } +// /// +// /// Initializes a new instance of the class. +// /// +// /// The HTTP context accessor. +// public PerWebRequestContainerProvider(IHttpContextAccessor httpContextAccessor) +// { +// this.httpContextAccessor = httpContextAccessor; +// } - /// - /// Gets the child container. - /// - /// - /// The child container. - /// - public ILifetimeScope CurrentScope - { - get - { - var httpContext = httpContextAccessor.GetCurrent(); +// /// +// /// Gets the child container. +// /// +// /// +// /// The child container. +// /// +// 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; +// } +// } - /// - /// Gets the lifetime scope. - /// - /// The context. - /// The child container. - public static ILifetimeScope GetLifetimeScope(HttpContextBase context) - { - return context.Items[PerWebRequestContainerKey] as ILifetimeScope; - } +// /// +// /// Gets the lifetime scope. +// /// +// /// The context. +// /// The child container. +// public static ILifetimeScope GetLifetimeScope(HttpContextBase context) +// { +// return context.Items[PerWebRequestContainerKey] as ILifetimeScope; +// } - /// - /// Disposes the managed resources. - /// - protected void DisposeManagedResources() - { - var httpContext = httpContextAccessor.GetCurrent(); - if (httpContext != null) - { - var requestContainer = httpContext.Items[PerWebRequestContainerKey] as ILifetimeScope; +// /// +// /// Disposes the managed resources. +// /// +// 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(); +// } +// } +// } - /// - /// Disposes the current scope. - /// - /// The sender. - /// The instance containing the event data. - 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(); - } - } - } - } - } -} \ No newline at end of file +// /// +// /// Disposes the current scope. +// /// +// /// The sender. +// /// The instance containing the event data. +// 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(); +// } +// } +// } +// } +// } +//} \ No newline at end of file diff --git a/vNext/src/BetterModules.Core.Web/Dependencies/PerWebRequestLifetimeModule.cs b/vNext/src/BetterModules.Core.Web/Dependencies/PerWebRequestLifetimeModule.cs index 13feb73..64bb644 100644 --- a/vNext/src/BetterModules.Core.Web/Dependencies/PerWebRequestLifetimeModule.cs +++ b/vNext/src/BetterModules.Core.Web/Dependencies/PerWebRequestLifetimeModule.cs @@ -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 -{ - /// - /// Per web request lifetime http module. - /// - public class PerWebRequestLifetimeModule : IHttpModule - { - /// - /// Indicates if module is starting. - /// - private static bool isStarting; +//namespace BetterModules.Core.Web.Dependencies +//{ +// /// +// /// Per web request lifetime http module. +// /// +// public class PerWebRequestLifetimeModule : IHttpModule +// { +// /// +// /// Indicates if module is starting. +// /// +// private static bool isStarting; - /// - /// Dynamic the module registration. - /// - public static void DynamicModuleRegistration() - { - if (!isStarting) - { - isStarting = true; - DynamicModuleUtility.RegisterModule(typeof(PerWebRequestLifetimeModule)); - } - } +// /// +// /// Dynamic the module registration. +// /// +// public static void DynamicModuleRegistration() +// { +// if (!isStarting) +// { +// isStarting = true; +// DynamicModuleUtility.RegisterModule(typeof(PerWebRequestLifetimeModule)); +// } +// } - /// - /// Disposes of the resources (other than memory) used by the module that implements . - /// - public void Dispose() - { - } +// /// +// /// Disposes of the resources (other than memory) used by the module that implements . +// /// +// public void Dispose() +// { +// } - /// - /// Initializes a module and prepares it to handle requests. - /// - /// An that provides access to the methods, properties, and events common to all application objects within an ASP.NET application - public void Init(HttpApplication context) - { - context.EndRequest += (sender, e) => - { - PerWebRequestContainerProvider.DisposeCurrentScope(sender, e); - }; - } - } -} \ No newline at end of file +// /// +// /// Initializes a module and prepares it to handle requests. +// /// +// /// An that provides access to the methods, properties, and events common to all application objects within an ASP.NET application +// public void Init(HttpApplication context) +// { +// context.EndRequest += (sender, e) => +// { +// PerWebRequestContainerProvider.DisposeCurrentScope(sender, e); +// }; +// } +// } +//} \ No newline at end of file diff --git a/vNext/src/BetterModules.Core.Web/Environment/Application/WebApplicationEntryPoint.cs b/vNext/src/BetterModules.Core.Web/Environment/Application/WebApplicationEntryPoint.cs index 3774b05..387a597 100644 --- a/vNext/src/BetterModules.Core.Web/Environment/Application/WebApplicationEntryPoint.cs +++ b/vNext/src/BetterModules.Core.Web/Environment/Application/WebApplicationEntryPoint.cs @@ -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 diff --git a/vNext/src/BetterModules.Core.Web/Environment/Application/WebApplicationPreStartManager.cs b/vNext/src/BetterModules.Core.Web/Environment/Application/WebApplicationPreStartManager.cs index 38cd8f6..06a1844 100644 --- a/vNext/src/BetterModules.Core.Web/Environment/Application/WebApplicationPreStartManager.cs +++ b/vNext/src/BetterModules.Core.Web/Environment/Application/WebApplicationPreStartManager.cs @@ -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; diff --git a/vNext/src/BetterModules.Core.Web/Environment/Assemblies/DefaultWebAssemblyManager.cs b/vNext/src/BetterModules.Core.Web/Environment/Assemblies/DefaultWebAssemblyManager.cs index 8036fb4..efd19a6 100644 --- a/vNext/src/BetterModules.Core.Web/Environment/Assemblies/DefaultWebAssemblyManager.cs +++ b/vNext/src/BetterModules.Core.Web/Environment/Assemblies/DefaultWebAssemblyManager.cs @@ -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 { @@ -22,8 +24,9 @@ public class DefaultWebAssemblyManager : DefaultAssemblyManager /// The embedded resources provider. /// The assembly loader. 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; } @@ -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); } diff --git a/vNext/src/BetterModules.Core.Web/Environment/Host/DefaultWebApplicationAutoHost.cs b/vNext/src/BetterModules.Core.Web/Environment/Host/DefaultWebApplicationAutoHost.cs index 3ce6581..cf4e590 100644 --- a/vNext/src/BetterModules.Core.Web/Environment/Host/DefaultWebApplicationAutoHost.cs +++ b/vNext/src/BetterModules.Core.Web/Environment/Host/DefaultWebApplicationAutoHost.cs @@ -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 { diff --git a/vNext/src/BetterModules.Core.Web/Environment/Host/UtilityHost.cs b/vNext/src/BetterModules.Core.Web/Environment/Host/UtilityHost.cs index f2e6c12..a26bd00 100644 --- a/vNext/src/BetterModules.Core.Web/Environment/Host/UtilityHost.cs +++ b/vNext/src/BetterModules.Core.Web/Environment/Host/UtilityHost.cs @@ -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; diff --git a/vNext/src/BetterModules.Core.Web/Modules/Registration/WebModuleRegistrationContext.cs b/vNext/src/BetterModules.Core.Web/Modules/Registration/WebModuleRegistrationContext.cs index 178878f..8f4da56 100644 --- a/vNext/src/BetterModules.Core.Web/Modules/Registration/WebModuleRegistrationContext.cs +++ b/vNext/src/BetterModules.Core.Web/Modules/Registration/WebModuleRegistrationContext.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using BetterModules.Core.Modules.Registration; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Routing; namespace BetterModules.Core.Web.Modules.Registration @@ -11,56 +12,56 @@ public class WebModuleRegistrationContext : ModuleRegistrationContext public WebModuleRegistrationContext(WebModuleDescriptor moduleDescriptor) : base(moduleDescriptor) { Namespaces = new HashSet(StringComparer.OrdinalIgnoreCase); - Routes = new RouteCollection(); + RouteBuilder = new RouteBuilder(); } protected ICollection Namespaces { get; private set; } - internal RouteCollection Routes { get; private set; } + internal IRouteBuilder RouteBuilder { get; private set; } public override string GetRegistrationName() { return ((WebModuleDescriptor)ModuleDescriptor).AreaName.ToLowerInvariant(); } - public Route MapRoute(string name, string url) + public IRouter MapRoute(string name, string url) { return MapRoute(name, url, null); } - public Route MapRoute(string name, string url, string[] namespaces) + public IRouter MapRoute(string name, string url, string[] namespaces) { return MapRoute(name, url, null, namespaces); } - public Route MapRoute(string name, string url, object defaults) + public IRouter MapRoute(string name, string url, object defaults) { return MapRoute(name, url, defaults, null); } - public Route MapRoute(string name, string url, object defaults, string[] namespaces) + public IRouter MapRoute(string name, string url, object defaults, string[] namespaces) { return MapRoute(name, url, defaults, null, namespaces); } - public Route MapRoute(string name, string url, object defaults, object constraints) + public IRouter MapRoute(string name, string url, object defaults, object constraints) { return MapRoute(name, url, defaults, constraints, null); } - public Route MapRoute(string name, string url, object defaults, object constraints, string[] namespaces) + public IRouter MapRoute(string name, string url, object defaults, object constraints, string[] namespaces) { if ((namespaces == null) && (this.Namespaces != null)) { namespaces = Namespaces.ToArray(); } - Route route = Routes.MapRoute(name, url, defaults, constraints, namespaces); + RouteBuilder.MapRoute(name, url, defaults, constraints, namespaces); + var router = RouteBuilder.Build(); route.DataTokens["area"] = ((WebModuleDescriptor)ModuleDescriptor).AreaName; bool flag = (namespaces == null) || (namespaces.Length == 0); route.DataTokens["UseNamespaceFallback"] = flag; - return route; } diff --git a/vNext/src/BetterModules.Core.Web/Mvc/CoreControllerBase.cs b/vNext/src/BetterModules.Core.Web/Mvc/CoreControllerBase.cs index 982dad4..fa2cf5e 100644 --- a/vNext/src/BetterModules.Core.Web/Mvc/CoreControllerBase.cs +++ b/vNext/src/BetterModules.Core.Web/Mvc/CoreControllerBase.cs @@ -5,7 +5,6 @@ using BetterModules.Core.Web.Mvc.Commands; using BetterModules.Core.Web.Mvc.Extensions; using Microsoft.AspNet.Mvc; -using Microsoft.AspNet.Mvc.Rendering; namespace BetterModules.Core.Web.Mvc { @@ -93,9 +92,7 @@ public virtual IMessagesIndicator Messages [NonAction] public virtual JsonResult Json(WireJson data/*, JsonRequestBehavior behavior = JsonRequestBehavior.DenyGet*/) { - List messages = data.Messages != null - ? data.Messages.ToList() - : new List(); + List messages = data.Messages?.ToList() ?? new List(); messages.AddRange(data.Success ? Messages.Success : Messages.Error); data.Messages = messages.ToArray(); diff --git a/vNext/src/BetterModules.Core.Web/Mvc/DefaultWebControllerFactory.cs b/vNext/src/BetterModules.Core.Web/Mvc/DefaultWebControllerFactory.cs index 9946907..59515e5 100644 --- a/vNext/src/BetterModules.Core.Web/Mvc/DefaultWebControllerFactory.cs +++ b/vNext/src/BetterModules.Core.Web/Mvc/DefaultWebControllerFactory.cs @@ -1,8 +1,5 @@ using System; -using System.Web.Mvc; -using System.Web.Routing; -using BetterModules.Core.Web.Dependencies; -using BetterModules.Core.Web.Mvc.Routes; +using System.Collections.Generic; using Microsoft.AspNet.Mvc; namespace BetterModules.Core.Web.Mvc @@ -12,58 +9,45 @@ namespace BetterModules.Core.Web.Mvc /// public class DefaultWebControllerFactory : DefaultControllerFactory { - private readonly PerWebRequestContainerProvider containerProvider; - - public DefaultWebControllerFactory(PerWebRequestContainerProvider containerProvider) + public DefaultWebControllerFactory(IControllerActivator controllerActivator, IEnumerable propertyActivators) + : base(controllerActivator, propertyActivators) { - this.containerProvider = containerProvider; } /// /// Retrieves the controller instance for the specified request context and controller type. /// - /// The context of the HTTP request, which includes the HTTP context and route data. + /// The context of the HTTP request, which includes the HTTP context and route data. /// The type of the controller. /// /// The controller instance. /// - protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) + protected Controller GetControllerInstance(ActionContext actionContext, Type controllerType) { - IController controller = null; + var provider = actionContext.HttpContext.RequestServices; + Controller controller = null; - if (controllerType != null && containerProvider.CurrentScope.IsRegistered(controllerType)) + if (controllerType != null) { - controller = containerProvider.CurrentScope.Resolve(controllerType) as IController; + controller = provider.GetService(controllerType) as Controller; } - return controller ?? base.GetControllerInstance(requestContext, controllerType); + return controller ?? (Controller)CreateController(actionContext); } /// - /// Retrieves the controller type for the specified name and request context. + /// Retrieves the controller type for the specified action context. /// - /// The context of the HTTP request, which includes the HTTP context and route data. - /// The name of the controller. + /// The context of the HTTP request, which includes the HTTP context and route data. /// /// The controller type. /// - protected override Type GetControllerType(RequestContext requestContext, string controllerName) + protected Type GetControllerType(ActionContext actionContext) { - var areaName = requestContext.RouteData.GetAreaName(); - - if (string.IsNullOrEmpty(areaName)) - { - return base.GetControllerType(requestContext, controllerName); - } - - string key = (areaName + "-" + controllerName + "Controller").ToUpperInvariant(); - if (containerProvider.CurrentScope.IsRegisteredWithKey(key)) - { - var controllerMetadata = containerProvider.CurrentScope.ResolveKeyed>(key); - return controllerMetadata.Metadata["ControllerType"] as Type; - } + // TODO: check if actionContext can be cast into ControllerActionDescriptor. If not, throw custom exception + var descriptor = (ControllerActionDescriptor)actionContext.ActionDescriptor; - return base.GetControllerType(requestContext, controllerName); + return descriptor.ControllerTypeInfo.AsType(); } } } diff --git a/vNext/src/BetterModules.Core.Web/Mvc/Extensions/ViewRenderingExtensions.cs b/vNext/src/BetterModules.Core.Web/Mvc/Extensions/ViewRenderingExtensions.cs index 61a37e0..5440c8e 100644 --- a/vNext/src/BetterModules.Core.Web/Mvc/Extensions/ViewRenderingExtensions.cs +++ b/vNext/src/BetterModules.Core.Web/Mvc/Extensions/ViewRenderingExtensions.cs @@ -24,8 +24,8 @@ public static string RenderViewToString(this CoreControllerBase controller, stri if (string.IsNullOrEmpty(viewName) || viewName.ToLower() == controller.ActionContext.ActionDescriptor.Name.ToLower()) { - var areaName = controller.ActionContext.RouteData.Values["area"]; - var controllerName = controller.ActionContext.RouteData.Values["controller"]; + var areaName = (string)controller.ActionContext.RouteData.Values["area"]; + var controllerName = (string)controller.ActionContext.RouteData.Values["controller"]; var actionName = controller.ActionContext.ActionDescriptor.Name; viewName = $"~/Areas/{areaName}/Views/{controllerName}/{actionName}.cshtml"; diff --git a/vNext/src/BetterModules.Core.Web/Mvc/Routes/DefaultRouteTable.cs b/vNext/src/BetterModules.Core.Web/Mvc/Routes/DefaultRouteTable.cs index 915ab6b..936d5ee 100644 --- a/vNext/src/BetterModules.Core.Web/Mvc/Routes/DefaultRouteTable.cs +++ b/vNext/src/BetterModules.Core.Web/Mvc/Routes/DefaultRouteTable.cs @@ -1,4 +1,4 @@ -using System.Web.Routing; +using Microsoft.AspNet.Routing; namespace BetterModules.Core.Web.Mvc.Routes { diff --git a/vNext/src/BetterModules.Core.Web/Mvc/Routes/IRouteTable.cs b/vNext/src/BetterModules.Core.Web/Mvc/Routes/IRouteTable.cs index 11d3236..191039c 100644 --- a/vNext/src/BetterModules.Core.Web/Mvc/Routes/IRouteTable.cs +++ b/vNext/src/BetterModules.Core.Web/Mvc/Routes/IRouteTable.cs @@ -1,4 +1,4 @@ -using System.Web.Routing; +using Microsoft.AspNet.Routing; namespace BetterModules.Core.Web.Mvc.Routes { diff --git a/vNext/src/BetterModules.Core.Web/Mvc/Routes/RouteExtensions.cs b/vNext/src/BetterModules.Core.Web/Mvc/Routes/RouteExtensions.cs index c2b2c15..c31a6f6 100644 --- a/vNext/src/BetterModules.Core.Web/Mvc/Routes/RouteExtensions.cs +++ b/vNext/src/BetterModules.Core.Web/Mvc/Routes/RouteExtensions.cs @@ -14,7 +14,7 @@ public static class RouteExtensions /// Area name. public static string GetAreaName(this RouteData routeData) { - return AreaHelpers.GetAreaName(routeData); + return routeData.Values["area"] as string; } } } diff --git a/vNext/src/BetterModules.Core.Web/Services/Caching/HttpRuntimeCacheService.cs b/vNext/src/BetterModules.Core.Web/Services/Caching/HttpRuntimeCacheService.cs index 89466dd..8c1958c 100644 --- a/vNext/src/BetterModules.Core.Web/Services/Caching/HttpRuntimeCacheService.cs +++ b/vNext/src/BetterModules.Core.Web/Services/Caching/HttpRuntimeCacheService.cs @@ -1,7 +1,4 @@ using System; -using System.Web; -using System.Web.Caching; -using Common.Logging; namespace BetterModules.Core.Web.Services.Caching { diff --git a/vNext/src/BetterModules.Core.Web/Web/DefaultHttpContextAccessor.cs b/vNext/src/BetterModules.Core.Web/Web/DefaultHttpContextAccessor.cs index 68ae6c6..340568b 100644 --- a/vNext/src/BetterModules.Core.Web/Web/DefaultHttpContextAccessor.cs +++ b/vNext/src/BetterModules.Core.Web/Web/DefaultHttpContextAccessor.cs @@ -3,7 +3,9 @@ using System.Reflection; using BetterModules.Core.Web.Configuration; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Extensions; using Microsoft.AspNet.Mvc; +using Microsoft.AspNet.Mvc.Rendering.Expressions; namespace BetterModules.Core.Web.Web { @@ -58,7 +60,7 @@ public string MapPath(string path) /// The absolute path that corresponds to path. public string MapPublicPath(string path) { - return string.Concat(GetServerUrl(new HttpRequestWrapper(HttpContext.Current.Request)).TrimEnd('/'), VirtualPathUtility.ToAbsolute(path)); + return string.Concat(GetServerUrl(GetCurrent().Request).TrimEnd('/'), VirtualPathUtility.ToAbsolute(path)); } /// @@ -72,14 +74,13 @@ public string MapPublicPath(string path) public string ResolveActionUrl(System.Linq.Expressions.Expression> expression, bool fullUrl = false) where TController : Controller { - var routeValuesFromExpression = Microsoft.Web.Mvc.Internal.ExpressionHelper.GetRouteValuesFromExpression(expression); + var routeValuesFromExpression = ExpressionHelper.GetRouteValuesFromExpression(expression); var action = routeValuesFromExpression["Action"].ToString(); var controller = routeValuesFromExpression["Controller"].ToString(); var current = GetCurrent(); - if (current != null) { - string url = new UrlHelper(current.Request.RequestContext).Action(action, controller, routeValuesFromExpression); + string url = new UrlHelper(current.).Action(action, controller, routeValuesFromExpression); if (fullUrl) { url = string.Concat(GetServerUrl(current.Request).TrimEnd('/'), url); @@ -98,17 +99,18 @@ public string ResolveActionUrl(System.Linq.Expressions.Expression /// The request. /// - private string GetServerUrl(HttpRequestBase request) + private string GetServerUrl(HttpRequest request) { + // TODO: Check if this is the right way to get server Url if (request != null && string.IsNullOrWhiteSpace(configuration.WebSiteUrl) || configuration.WebSiteUrl.Equals("auto", StringComparison.InvariantCultureIgnoreCase)) { - var url = request.Url.AbsoluteUri; - var query = HttpContext.Current.Request.Url.PathAndQuery; - if (!string.IsNullOrEmpty(query) && query != "/") - { - url = url.Replace(query, null); - } + var url = request?.Host.Value; + //var query = HttpContext.Current.Request.Url.PathAndQuery; + //if (!string.IsNullOrEmpty(query) && query != "/") + //{ + // url = url.Replace(query, null); + //} return url; } diff --git a/vNext/src/BetterModules.Core.Web/Web/EmbeddedResources/EmbeddedResourcesVirtualFile.cs b/vNext/src/BetterModules.Core.Web/Web/EmbeddedResources/EmbeddedResourcesVirtualFile.cs index 0650c23..46ba401 100644 --- a/vNext/src/BetterModules.Core.Web/Web/EmbeddedResources/EmbeddedResourcesVirtualFile.cs +++ b/vNext/src/BetterModules.Core.Web/Web/EmbeddedResources/EmbeddedResourcesVirtualFile.cs @@ -1,6 +1,5 @@ using System.IO; using System.Reflection; -using System.Web.Hosting; namespace BetterModules.Core.Web.Web.EmbeddedResources { diff --git a/vNext/src/BetterModules.Core.Web/Web/EmbeddedResources/EmbeddedResourcesVirtualPathProvider.cs b/vNext/src/BetterModules.Core.Web/Web/EmbeddedResources/EmbeddedResourcesVirtualPathProvider.cs index a763692..dd99b6e 100644 --- a/vNext/src/BetterModules.Core.Web/Web/EmbeddedResources/EmbeddedResourcesVirtualPathProvider.cs +++ b/vNext/src/BetterModules.Core.Web/Web/EmbeddedResources/EmbeddedResourcesVirtualPathProvider.cs @@ -1,8 +1,6 @@ using System; using System.Collections; using System.Linq; -using System.Web.Caching; -using System.Web.Hosting; namespace BetterModules.Core.Web.Web.EmbeddedResources {