Resvolution - UmbracoApiControllerResolver

This commit is contained in:
Stephan
2016-08-19 14:44:56 +02:00
parent cac14d57eb
commit 169735dab9
9 changed files with 34 additions and 39 deletions

View File

@@ -23,7 +23,6 @@ namespace Umbraco.Tests.Routing
[TestFixture]
public class RenderRouteHandlerTests : BaseRoutingTest
{
public override void Initialize()
{
base.Initialize();
@@ -44,9 +43,10 @@ namespace Umbraco.Tests.Routing
SurfaceControllerResolver.Current = new SurfaceControllerResolver(
new ActivatorServiceProvider(), Logger,
PluginManager.Current.ResolveSurfaceControllers());
UmbracoApiControllerResolver.Current = new UmbracoApiControllerResolver(
new ActivatorServiceProvider(), Logger,
PluginManager.Current.ResolveUmbracoApiControllers());
var umbracoApiControllerTypes = new UmbracoApiControllerTypeCollection(PluginManager.Current.ResolveUmbracoApiControllers());
Container.RegisterInstance(umbracoApiControllerTypes);
ShortStringHelperResolver.Current = new ShortStringHelperResolver(new DefaultShortStringHelper(SettingsForTests.GetDefault()));
base.FreezeResolution();

View File

@@ -11,6 +11,7 @@ using Umbraco.Web.Editors;
using Umbraco.Web.HealthCheck;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Web.WebApi;
using Umbraco.Web._Legacy.Actions;
using CoreCurrent = Umbraco.Core.DependencyInjection.Current;
@@ -145,6 +146,9 @@ namespace Umbraco.Web
internal static XsltExtensionCollection XsltExtensions
=> Container.GetInstance<XsltExtensionCollection>();
internal static UmbracoApiControllerTypeCollection UmbracoApiControllerTypes
=> Container.GetInstance<UmbracoApiControllerTypeCollection>();
#endregion
#region Core Getters

View File

@@ -56,7 +56,7 @@ namespace Umbraco.Web
var area = "";
var apiController = UmbracoApiControllerResolver.Current.RegisteredUmbracoApiControllers
var apiController = Current.UmbracoApiControllerTypes
.SingleOrDefault(x => x == apiControllerType);
if (apiController == null)
throw new InvalidOperationException("Could not find the umbraco api controller of type " + apiControllerType.FullName);

View File

@@ -31,9 +31,9 @@ namespace Umbraco.Web.Trees
internal static Attempt<Type> TryGetControllerTree(this ApplicationTree appTree)
{
//get reference to all TreeApiControllers
var controllerTrees = UmbracoApiControllerResolver.Current.RegisteredUmbracoApiControllers
.Where(TypeHelper.IsTypeAssignableFrom<TreeController>)
.ToArray();
var controllerTrees = Current.UmbracoApiControllerTypes
.Where(TypeHelper.IsTypeAssignableFrom<TreeController>)
.ToArray();
//find the one we're looking for
var foundControllerTree = controllerTrees.FirstOrDefault(x => x == appTree.GetRuntimeType());

View File

@@ -288,6 +288,7 @@
<Compile Include="umbraco.presentation\umbraco\endPreview.aspx.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="WebApi\UmbracoApiControllerTypeCollection.cs" />
<Compile Include="WebServices\FacadeStatusController.cs" />
<Compile Include="WebServices\NuCacheStatusController.cs" />
<Compile Include="_Legacy\Actions\Action.cs" />
@@ -916,7 +917,6 @@
<Compile Include="WebApi\PrefixlessBodyModelValidatorAttribute.cs" />
<Compile Include="WebApi\UmbracoApiController.cs" />
<Compile Include="WebApi\UmbracoApiControllerBase.cs" />
<Compile Include="WebApi\UmbracoApiControllerResolver.cs" />
<Compile Include="Mvc\UmbracoAuthorizeAttribute.cs" />
<Compile Include="Mvc\NotChildAction.cs" />
<Compile Include="Mvc\UmbracoAuthorizedController.cs" />

View File

@@ -96,7 +96,7 @@ namespace Umbraco.Web
var area = "";
var apiController = UmbracoApiControllerResolver.Current.RegisteredUmbracoApiControllers
var apiController = Current.UmbracoApiControllerTypes
.SingleOrDefault(x => x == apiControllerType);
if (apiController == null)
throw new InvalidOperationException("Could not find the umbraco api controller of type " + apiControllerType.FullName);

View File

@@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Logging;
using Umbraco.Core.ObjectResolution;
namespace Umbraco.Web.WebApi
{
internal sealed class UmbracoApiControllerResolver : ManyObjectsResolverBase<UmbracoApiControllerResolver, UmbracoApiController>
{
public UmbracoApiControllerResolver(IServiceProvider serviceProvider, ILogger logger, IEnumerable<Type> apiControllers)
: base(serviceProvider, logger, apiControllers)
{
}
/// <summary>
/// Gets all of the umbraco api controller types
/// </summary>
public IEnumerable<Type> RegisteredUmbracoApiControllers
{
get { return InstanceTypes; }
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.DependencyInjection;
namespace Umbraco.Web.WebApi
{
// 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 UmbracoApiControllerTypeCollection : BuilderCollectionBase<Type>
{
public UmbracoApiControllerTypeCollection(IEnumerable<Type> items)
: base(items)
{ }
}
}

View File

@@ -250,7 +250,7 @@ namespace Umbraco.Web
//we need to find the plugin controllers and route them
var pluginControllers =
SurfaceControllerResolver.Current.RegisteredSurfaceControllers.Concat(
UmbracoApiControllerResolver.Current.RegisteredUmbracoApiControllers).ToArray();
Current.UmbracoApiControllerTypes).ToArray();
//local controllers do not contain the attribute
var localControllers = pluginControllers.Where(x => PluginController.GetMetadata(x).AreaName.IsNullOrWhiteSpace());
@@ -485,9 +485,8 @@ namespace Umbraco.Web
ServiceProvider, ProfilingLogger.Logger,
PluginManager.ResolveSurfaceControllers());
UmbracoApiControllerResolver.Current = new UmbracoApiControllerResolver(
ServiceProvider, ProfilingLogger.Logger,
PluginManager.ResolveUmbracoApiControllers());
var umbracoApiControllerTypes = new UmbracoApiControllerTypeCollection(PluginManager.ResolveUmbracoApiControllers());
Container.RegisterInstance(umbracoApiControllerTypes);
// both TinyMceValueConverter (in Core) and RteMacroRenderingValueConverter (in Web) will be
// discovered when CoreBootManager configures the converters. We HAVE to remove one of them