removes module injector and other migrated code
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
using System.Web;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Exceptions;
|
||||
|
||||
namespace Umbraco.Web.Composing
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a base class for module injectors.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModule">The type of the injected module.</typeparam>
|
||||
public abstract class ModuleInjector<TModule> : IHttpModule
|
||||
where TModule : class, IHttpModule
|
||||
{
|
||||
protected TModule Module { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Init(HttpApplication context)
|
||||
{
|
||||
try
|
||||
{
|
||||
// using the service locator here - no other way, really
|
||||
Module = Current.Factory.GetRequiredService<TModule>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if GetInstance fails, it may be because of a boot error, in
|
||||
// which case that is the error we actually want to report
|
||||
IRuntimeState runtimeState = null;
|
||||
|
||||
try
|
||||
{
|
||||
runtimeState = Current.Factory.GetRequiredService<IRuntimeState>();
|
||||
}
|
||||
catch { /* don't make it worse */ }
|
||||
|
||||
if (runtimeState?.BootFailedException != null)
|
||||
BootFailedException.Rethrow(runtimeState.BootFailedException);
|
||||
|
||||
// else... throw what we have
|
||||
throw;
|
||||
}
|
||||
|
||||
// initialize
|
||||
Module.Init(context);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
Module?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.WebApi;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
/// <summary>
|
||||
/// A custom area for controllers that are plugins
|
||||
/// </summary>
|
||||
internal class PluginControllerArea : AreaRegistration
|
||||
{
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IEnumerable<PluginControllerMetadata> _surfaceControllers;
|
||||
private readonly IEnumerable<PluginControllerMetadata> _apiControllers;
|
||||
private readonly string _areaName;
|
||||
|
||||
/// <summary>
|
||||
/// The constructor accepts all types of plugin controllers and will verify that ALL of them have the same areaName assigned to them
|
||||
/// based on their PluginControllerAttribute. If they are not the same an exception will be thrown.
|
||||
/// </summary>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="pluginControllers"></param>
|
||||
public PluginControllerArea(GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IEnumerable<PluginControllerMetadata> pluginControllers)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
var controllers = pluginControllers.ToArray();
|
||||
|
||||
if (controllers.Any(x => x.AreaName.IsNullOrWhiteSpace()))
|
||||
{
|
||||
throw new InvalidOperationException("Cannot create a PluginControllerArea unless all plugin controllers assigned have a PluginControllerAttribute assigned");
|
||||
}
|
||||
_areaName = controllers.First().AreaName;
|
||||
foreach(var c in controllers)
|
||||
{
|
||||
if (c.AreaName != _areaName)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot create a PluginControllerArea unless all plugin controllers assigned have the same AreaName. The first AreaName found was " + _areaName + " however, the controller of type " + c.GetType().FullName + " has an AreaName of " + c.AreaName);
|
||||
}
|
||||
}
|
||||
|
||||
//get the controllers
|
||||
_surfaceControllers = controllers.Where(x => TypeHelper.IsTypeAssignableFrom<SurfaceController>(x.ControllerType));
|
||||
_apiControllers = controllers.Where(x => TypeHelper.IsTypeAssignableFrom<UmbracoApiController>(x.ControllerType));
|
||||
}
|
||||
|
||||
public override void RegisterArea(AreaRegistrationContext context)
|
||||
{
|
||||
MapRouteSurfaceControllers(context.Routes, _surfaceControllers);
|
||||
MapRouteApiControllers(context.Routes, _apiControllers);
|
||||
}
|
||||
|
||||
public override string AreaName
|
||||
{
|
||||
get { return _areaName; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers all surface controller routes
|
||||
/// </summary>
|
||||
/// <param name="routes"></param>
|
||||
/// <param name="surfaceControllers"></param>
|
||||
/// <remarks>
|
||||
/// The routes will be:
|
||||
///
|
||||
/// /Umbraco/[AreaName]/[ControllerName]/[Action]/[Id]
|
||||
/// </remarks>
|
||||
private void MapRouteSurfaceControllers(RouteCollection routes, IEnumerable<PluginControllerMetadata> surfaceControllers)
|
||||
{
|
||||
foreach (var s in surfaceControllers)
|
||||
{
|
||||
var route = this.RouteControllerPlugin(_globalSettings, _hostingEnvironment, s.ControllerName, s.ControllerType, routes, "", "Index", UrlParameter.Optional, "surface");
|
||||
//set the route handler to our SurfaceRouteHandler
|
||||
route.RouteHandler = new SurfaceRouteHandler();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers all api controller routes
|
||||
/// </summary>
|
||||
/// <param name="routes"></param>
|
||||
/// <param name="apiControllers"></param>
|
||||
private void MapRouteApiControllers(RouteCollection routes, IEnumerable<PluginControllerMetadata> apiControllers)
|
||||
{
|
||||
foreach (var s in apiControllers)
|
||||
{
|
||||
this.RouteControllerPlugin(_globalSettings, _hostingEnvironment, s.ControllerName, s.ControllerType, routes, "", "", UrlParameter.Optional, "api",
|
||||
isMvc: false,
|
||||
areaPathPrefix: s.IsBackOffice ? "backoffice" : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,82 +116,8 @@ namespace Umbraco.Web.Runtime
|
||||
umbracoPath + "/RenderMvc/{action}/{id}",
|
||||
new { controller = "RenderMvc", action = "Index", id = UrlParameter.Optional }
|
||||
);
|
||||
|
||||
defaultRoute.RouteHandler = new RenderRouteHandler(umbracoContextAccessor, ControllerBuilder.Current.GetControllerFactory(), shortStringHelper);
|
||||
|
||||
// register install routes
|
||||
// RouteTable.Routes.RegisterArea<UmbracoInstallArea>();
|
||||
|
||||
// register all back office routes
|
||||
// RouteTable.Routes.RegisterArea(new BackOfficeArea(globalSettings, hostingEnvironment));
|
||||
|
||||
// plugin controllers must come first because the next route will catch many things
|
||||
RoutePluginControllers(globalSettings, apiControllerTypes, hostingEnvironment);
|
||||
}
|
||||
|
||||
private static void RoutePluginControllers(
|
||||
GlobalSettings globalSettings,
|
||||
UmbracoApiControllerTypeCollection apiControllerTypes,
|
||||
IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
var umbracoPath = globalSettings.GetUmbracoMvcArea(hostingEnvironment);
|
||||
|
||||
// need to find the plugin controllers and route them
|
||||
var pluginControllers = apiControllerTypes; //TODO was: surfaceControllerTypes.Concat(apiControllerTypes).ToArray();
|
||||
|
||||
// local controllers do not contain the attribute
|
||||
var localControllers = pluginControllers.Where(x => PluginController.GetMetadata(x).AreaName.IsNullOrWhiteSpace());
|
||||
foreach (var s in localControllers)
|
||||
{
|
||||
if (TypeHelper.IsTypeAssignableFrom<SurfaceController>(s))
|
||||
RouteLocalSurfaceController(s, umbracoPath);
|
||||
else if (TypeHelper.IsTypeAssignableFrom<UmbracoApiController>(s))
|
||||
RouteLocalApiController(s, umbracoPath);
|
||||
}
|
||||
|
||||
// get the plugin controllers that are unique to each area (group by)
|
||||
var pluginSurfaceControlleres = pluginControllers.Where(x => PluginController.GetMetadata(x).AreaName.IsNullOrWhiteSpace() == false);
|
||||
var groupedAreas = pluginSurfaceControlleres.GroupBy(controller => PluginController.GetMetadata(controller).AreaName);
|
||||
// loop through each area defined amongst the controllers
|
||||
foreach (var g in groupedAreas)
|
||||
{
|
||||
// create & register an area for the controllers (this will throw an exception if all controllers are not in the same area)
|
||||
var pluginControllerArea = new PluginControllerArea(globalSettings, hostingEnvironment, g.Select(PluginController.GetMetadata));
|
||||
RouteTable.Routes.RegisterArea(pluginControllerArea);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RouteLocalApiController(Type controller, string umbracoPath)
|
||||
{
|
||||
var meta = PluginController.GetMetadata(controller);
|
||||
var url = umbracoPath + (meta.IsBackOffice ? "/BackOffice" : "") + "/Api/" + meta.ControllerName + "/{action}/{id}";
|
||||
var route = RouteTable.Routes.MapHttpRoute(
|
||||
$"umbraco-api-{meta.ControllerName}",
|
||||
url, // URL to match
|
||||
new { controller = meta.ControllerName, id = UrlParameter.Optional },
|
||||
new[] { meta.ControllerNamespace });
|
||||
if (route.DataTokens == null) // web api routes don't set the data tokens object
|
||||
route.DataTokens = new RouteValueDictionary();
|
||||
|
||||
// TODO: Pretty sure this is not necessary, we'll see
|
||||
//route.DataTokens.Add(Core.Constants.Web.UmbracoDataToken, "api"); //ensure the umbraco token is set
|
||||
}
|
||||
|
||||
private static void RouteLocalSurfaceController(Type controller, string umbracoPath)
|
||||
{
|
||||
var meta = PluginController.GetMetadata(controller);
|
||||
var url = umbracoPath + "/Surface/" + meta.ControllerName + "/{action}/{id}";
|
||||
var route = RouteTable.Routes.MapRoute(
|
||||
$"umbraco-surface-{meta.ControllerName}",
|
||||
url, // URL to match
|
||||
new { controller = meta.ControllerName, action = "Index", id = UrlParameter.Optional },
|
||||
new[] { meta.ControllerNamespace }); // look in this namespace to create the controller
|
||||
|
||||
// TODO: Pretty sure this is not necessary, we'll see
|
||||
//route.DataTokens.Add(Core.Constants.Web.UmbracoDataToken, "surface"); // ensure the umbraco token is set
|
||||
|
||||
route.DataTokens.Add("UseNamespaceFallback", false); // don't look anywhere else except this namespace!
|
||||
// make it use our custom/special SurfaceMvcHandler
|
||||
route.RouteHandler = new SurfaceRouteHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,6 @@
|
||||
<Compile Include="WebApi\ParameterSwapControllerActionSelector.cs" />
|
||||
<Compile Include="HttpContextUmbracoContextAccessor.cs" />
|
||||
<Compile Include="IHttpContextAccessor.cs" />
|
||||
<Compile Include="Composing\ModuleInjector.cs" />
|
||||
<Compile Include="WebApi\EnableDetailedErrorsAttribute.cs" />
|
||||
<Compile Include="WebApi\Filters\FeatureAuthorizeAttribute.cs" />
|
||||
<Compile Include="WebApi\SessionHttpControllerRouteHandler.cs" />
|
||||
@@ -224,7 +223,6 @@
|
||||
<DependentUpon>Strings.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Mvc\SurfaceController.cs" />
|
||||
<Compile Include="Mvc\PluginControllerArea.cs" />
|
||||
<Compile Include="Mvc\PluginControllerAttribute.cs" />
|
||||
<Compile Include="Mvc\UmbracoPageResult.cs" />
|
||||
<Compile Include="RouteCollectionExtensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user