Resvolution - SurfaceControllerResolver
This commit is contained in:
@@ -40,9 +40,8 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
DefaultRenderMvcControllerResolver.Current = new DefaultRenderMvcControllerResolver(typeof(RenderMvcController));
|
||||
|
||||
SurfaceControllerResolver.Current = new SurfaceControllerResolver(
|
||||
new ActivatorServiceProvider(), Logger,
|
||||
PluginManager.Current.ResolveSurfaceControllers());
|
||||
var surfaceControllerTypes = new SurfaceControllerTypeCollection(PluginManager.Current.ResolveSurfaceControllers());
|
||||
Container.RegisterInstance(surfaceControllerTypes);
|
||||
|
||||
var umbracoApiControllerTypes = new UmbracoApiControllerTypeCollection(PluginManager.Current.ResolveUmbracoApiControllers());
|
||||
Container.RegisterInstance(umbracoApiControllerTypes);
|
||||
|
||||
@@ -9,6 +9,7 @@ using Umbraco.Core.Strings;
|
||||
using Umbraco.Core._Legacy.PackageActions;
|
||||
using Umbraco.Web.Editors;
|
||||
using Umbraco.Web.HealthCheck;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.WebApi;
|
||||
@@ -149,6 +150,9 @@ namespace Umbraco.Web
|
||||
internal static UmbracoApiControllerTypeCollection UmbracoApiControllerTypes
|
||||
=> Container.GetInstance<UmbracoApiControllerTypeCollection>();
|
||||
|
||||
internal static SurfaceControllerTypeCollection SurfaceControllerTypes
|
||||
=> Container.GetInstance<SurfaceControllerTypeCollection>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Core Getters
|
||||
|
||||
@@ -176,8 +176,7 @@ namespace Umbraco.Web
|
||||
|
||||
var routeVals = new RouteValueDictionary(new {area = ""});
|
||||
|
||||
var surfaceController = SurfaceControllerResolver.Current.RegisteredSurfaceControllers
|
||||
.SingleOrDefault(x => x == surfaceType);
|
||||
var surfaceController = Current.SurfaceControllerTypes.SingleOrDefault(x => x == surfaceType);
|
||||
if (surfaceController == null)
|
||||
throw new InvalidOperationException("Could not find the surface controller of type " + surfaceType.FullName);
|
||||
var metaData = PluginController.GetMetadata(surfaceController);
|
||||
@@ -637,8 +636,7 @@ namespace Umbraco.Web
|
||||
|
||||
var area = "";
|
||||
|
||||
var surfaceController = SurfaceControllerResolver.Current.RegisteredSurfaceControllers
|
||||
.SingleOrDefault(x => x == surfaceType);
|
||||
var surfaceController = Current.SurfaceControllerTypes.SingleOrDefault(x => x == surfaceType);
|
||||
if (surfaceController == null)
|
||||
throw new InvalidOperationException("Could not find the surface controller of type " + surfaceType.FullName);
|
||||
var metaData = PluginController.GetMetadata(surfaceController);
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
internal sealed class SurfaceControllerResolver : ManyObjectsResolverBase<SurfaceControllerResolver, SurfaceController>
|
||||
{
|
||||
public SurfaceControllerResolver(IServiceProvider serviceProvider, ILogger logger, IEnumerable<Type> surfaceControllers)
|
||||
: base(serviceProvider, logger, surfaceControllers)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the surface controllers
|
||||
/// </summary>
|
||||
[Obsolete("This property should not be used in code, controllers are to be instantiated via MVC. To get a list of SurfaceController types use the RegisteredSurfaceControllers property.")]
|
||||
public IEnumerable<SurfaceController> SurfaceControllers
|
||||
{
|
||||
get { return Values; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all of the surface controller types
|
||||
/// </summary>
|
||||
public IEnumerable<Type> RegisteredSurfaceControllers
|
||||
{
|
||||
get { return InstanceTypes; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
17
src/Umbraco.Web/Mvc/SurfaceControllerTypeCollection.cs
Normal file
17
src/Umbraco.Web/Mvc/SurfaceControllerTypeCollection.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.DependencyInjection;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
// unless we want to modify the content of the collection
|
||||
// which we are not doing at the moment
|
||||
// we can inherit from BuilderCollectionBase and just be enumerable
|
||||
|
||||
internal class SurfaceControllerTypeCollection : BuilderCollectionBase<Type>
|
||||
{
|
||||
public SurfaceControllerTypeCollection(IEnumerable<Type> items)
|
||||
: base(items)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -216,6 +216,7 @@
|
||||
<Compile Include="Editors\IEditorValidator.cs" />
|
||||
<Compile Include="Editors\EditorModelEventManager.cs" />
|
||||
<Compile Include="HtmlHelperBackOfficeExtensions.cs" />
|
||||
<Compile Include="Mvc\SurfaceControllerTypeCollection.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\PublishedFragmentProperty.cs" />
|
||||
<Compile Include="PublishedCache\PublishedFragment.cs" />
|
||||
<Compile Include="PublishedCache\PublishedFragmentProperty.cs" />
|
||||
@@ -968,7 +969,6 @@
|
||||
<Compile Include="Routing\AliasUrlProvider.cs" />
|
||||
<Compile Include="Routing\ContentFinderByLegacy404.cs" />
|
||||
<Compile Include="Routing\ContentFinderByPageIdQuery.cs" />
|
||||
<Compile Include="Mvc\SurfaceControllerResolver.cs" />
|
||||
<Compile Include="Routing\ISiteDomainHelper.cs" />
|
||||
<Compile Include="Routing\RoutableAttemptEventArgs.cs" />
|
||||
<Compile Include="Routing\DefaultUrlProvider.cs" />
|
||||
|
||||
@@ -291,8 +291,7 @@ namespace Umbraco.Web
|
||||
|
||||
var area = "";
|
||||
|
||||
var surfaceController = SurfaceControllerResolver.Current.RegisteredSurfaceControllers
|
||||
.SingleOrDefault(x => x == surfaceType);
|
||||
var surfaceController = Current.SurfaceControllerTypes.SingleOrDefault(x => x == surfaceType);
|
||||
if (surfaceController == null)
|
||||
throw new InvalidOperationException("Could not find the surface controller of type " + surfaceType.FullName);
|
||||
var metaData = PluginController.GetMetadata(surfaceController);
|
||||
|
||||
@@ -248,9 +248,9 @@ namespace Umbraco.Web
|
||||
var umbracoPath = GlobalSettings.UmbracoMvcArea;
|
||||
|
||||
//we need to find the plugin controllers and route them
|
||||
var pluginControllers =
|
||||
SurfaceControllerResolver.Current.RegisteredSurfaceControllers.Concat(
|
||||
Current.UmbracoApiControllerTypes).ToArray();
|
||||
var pluginControllers = Current.SurfaceControllerTypes
|
||||
.Concat(Current.UmbracoApiControllerTypes)
|
||||
.ToArray();
|
||||
|
||||
//local controllers do not contain the attribute
|
||||
var localControllers = pluginControllers.Where(x => PluginController.GetMetadata(x).AreaName.IsNullOrWhiteSpace());
|
||||
@@ -481,9 +481,8 @@ namespace Umbraco.Web
|
||||
ActionCollectionBuilder.Register(Container)
|
||||
.SetProducer(() => PluginManager.ResolveActions());
|
||||
|
||||
SurfaceControllerResolver.Current = new SurfaceControllerResolver(
|
||||
ServiceProvider, ProfilingLogger.Logger,
|
||||
PluginManager.ResolveSurfaceControllers());
|
||||
var surfaceControllerTypes = new SurfaceControllerTypeCollection(PluginManager.ResolveSurfaceControllers());
|
||||
Container.RegisterInstance(surfaceControllerTypes);
|
||||
|
||||
var umbracoApiControllerTypes = new UmbracoApiControllerTypeCollection(PluginManager.ResolveUmbracoApiControllers());
|
||||
Container.RegisterInstance(umbracoApiControllerTypes);
|
||||
|
||||
Reference in New Issue
Block a user