diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index 6553ac5116..5dab95a6c9 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -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(); diff --git a/src/Umbraco.Web/Current.cs b/src/Umbraco.Web/Current.cs index e56ee2d7a5..42f07160b5 100644 --- a/src/Umbraco.Web/Current.cs +++ b/src/Umbraco.Web/Current.cs @@ -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(); + internal static UmbracoApiControllerTypeCollection UmbracoApiControllerTypes + => Container.GetInstance(); + #endregion #region Core Getters diff --git a/src/Umbraco.Web/HttpUrlHelperExtensions.cs b/src/Umbraco.Web/HttpUrlHelperExtensions.cs index 1b04a7dd8f..a88e702e4b 100644 --- a/src/Umbraco.Web/HttpUrlHelperExtensions.cs +++ b/src/Umbraco.Web/HttpUrlHelperExtensions.cs @@ -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); diff --git a/src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs b/src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs index a2a52c8ddb..4752e4d068 100644 --- a/src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs +++ b/src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs @@ -31,9 +31,9 @@ namespace Umbraco.Web.Trees internal static Attempt TryGetControllerTree(this ApplicationTree appTree) { //get reference to all TreeApiControllers - var controllerTrees = UmbracoApiControllerResolver.Current.RegisteredUmbracoApiControllers - .Where(TypeHelper.IsTypeAssignableFrom) - .ToArray(); + var controllerTrees = Current.UmbracoApiControllerTypes + .Where(TypeHelper.IsTypeAssignableFrom) + .ToArray(); //find the one we're looking for var foundControllerTree = controllerTrees.FirstOrDefault(x => x == appTree.GetRuntimeType()); diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 832f347ed4..e6a5f31f0f 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -288,6 +288,7 @@ ASPXCodeBehind + @@ -916,7 +917,6 @@ - diff --git a/src/Umbraco.Web/UrlHelperExtensions.cs b/src/Umbraco.Web/UrlHelperExtensions.cs index 1893a36c89..e196e0fc52 100644 --- a/src/Umbraco.Web/UrlHelperExtensions.cs +++ b/src/Umbraco.Web/UrlHelperExtensions.cs @@ -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); diff --git a/src/Umbraco.Web/WebApi/UmbracoApiControllerResolver.cs b/src/Umbraco.Web/WebApi/UmbracoApiControllerResolver.cs deleted file mode 100644 index cea26b8de7..0000000000 --- a/src/Umbraco.Web/WebApi/UmbracoApiControllerResolver.cs +++ /dev/null @@ -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 - { - public UmbracoApiControllerResolver(IServiceProvider serviceProvider, ILogger logger, IEnumerable apiControllers) - : base(serviceProvider, logger, apiControllers) - { - - } - - /// - /// Gets all of the umbraco api controller types - /// - public IEnumerable RegisteredUmbracoApiControllers - { - get { return InstanceTypes; } - } - - } -} \ No newline at end of file diff --git a/src/Umbraco.Web/WebApi/UmbracoApiControllerTypeCollection.cs b/src/Umbraco.Web/WebApi/UmbracoApiControllerTypeCollection.cs new file mode 100644 index 0000000000..9cfc197497 --- /dev/null +++ b/src/Umbraco.Web/WebApi/UmbracoApiControllerTypeCollection.cs @@ -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 + { + public UmbracoApiControllerTypeCollection(IEnumerable items) + : base(items) + { } + } +} diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index 690e0a0d76..da720e973c 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -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