diff --git a/src/Umbraco.Web/LightInjectExtensions.cs b/src/Umbraco.Web/LightInjectExtensions.cs index 247afe0926..04ffca0f20 100644 --- a/src/Umbraco.Web/LightInjectExtensions.cs +++ b/src/Umbraco.Web/LightInjectExtensions.cs @@ -14,17 +14,14 @@ namespace Umbraco.Web /// /// /// - public static void RegisterMvcControllers(this IServiceRegistry container, PluginManager pluginManager) + /// + public static void RegisterMvcControllers(this IServiceRegistry container, PluginManager pluginManager, Assembly assembly) { - //TODO: We've already scanned for UmbracoApiControllers and SurfaceControllers - should we scan again + //TODO: We've already scanned for UmbracoApiControllers and SurfaceControllers - should we scan again // for all controllers? Seems like we should just do this once and then filter. That said here we are // only scanning our own single assembly. Hrm. - var types = pluginManager.ResolveTypes(specificAssemblies: new[] { Assembly.GetCallingAssembly() }); - foreach (var type in types) - { - container.Register(type, new PerRequestLifeTime()); - } + container.RegisterControllers(pluginManager, assembly); } /// @@ -32,18 +29,21 @@ namespace Umbraco.Web /// /// /// - public static void RegisterApiControllers(this IServiceRegistry container, PluginManager pluginManager) + /// + public static void RegisterApiControllers(this IServiceRegistry container, PluginManager pluginManager, Assembly assembly) { - //TODO: We've already scanned for UmbracoApiControllers and SurfaceControllers - should we scan again + //TODO: We've already scanned for UmbracoApiControllers and SurfaceControllers - should we scan again // for all controllers? Seems like we should just do this once and then filter. That said here we are // only scanning our own single assembly. Hrm. - var types = pluginManager.ResolveTypes(specificAssemblies: new[] { Assembly.GetCallingAssembly() }); - foreach (var type in types) - { - container.Register(type, new PerRequestLifeTime()); - } + container.RegisterControllers(pluginManager, assembly); } + private static void RegisterControllers(this IServiceRegistry container, PluginManager pluginManager, Assembly assembly) + { + var types = pluginManager.ResolveTypes(specificAssemblies: new[] { assembly }); + foreach (var type in types) + container.Register(type, new PerRequestLifeTime()); + } } } diff --git a/src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs b/src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs index 070ee2c8dc..a2a52c8ddb 100644 --- a/src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs +++ b/src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs @@ -128,20 +128,22 @@ namespace Umbraco.Web.Trees : Attempt.Succeed(node); } - internal static Attempt TryLoadFromControllerTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, HttpControllerContext controllerContext) + internal static Attempt TryLoadFromControllerTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, HttpControllerContext controllerContext) { var foundControllerTreeAttempt = appTree.TryGetControllerTree(); if (foundControllerTreeAttempt.Success == false) - { return Attempt.Fail(foundControllerTreeAttempt.Exception); - } - var foundControllerTree = foundControllerTreeAttempt.Result; - //instantiate it, since we are proxying, we need to setup the instance with our current context - var instance = (TreeController)DependencyResolver.Current.GetService(foundControllerTree); + // instantiate it, since we are proxying, we need to setup the instance with our current context + var foundControllerTree = foundControllerTreeAttempt.Result; + var instance = (TreeController) DependencyResolver.Current.GetService(foundControllerTree); + if (instance == null) + throw new Exception("Failed to get tree " + foundControllerTree.FullName + "."); + instance.ControllerContext = controllerContext; instance.Request = controllerContext.Request; - //return it's data + + // return its data return Attempt.Succeed(instance.GetNodes(id, formCollection)); } diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index a7e3345067..fbfc11f92d 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -26,7 +26,6 @@ using Umbraco.Web.Media; using Umbraco.Web.Media.ThumbnailProviders; using Umbraco.Web.Mvc; using Umbraco.Web.PublishedCache; -using Umbraco.Web.PublishedCache.XmlPublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; using Umbraco.Web.UI.JavaScript; @@ -40,7 +39,6 @@ using Umbraco.Core.DependencyInjection; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Services.Changes; -using Umbraco.Core.Strings; using Umbraco.Web.Cache; using Umbraco.Web.DependencyInjection; using Umbraco.Web.HealthCheck; @@ -394,9 +392,9 @@ namespace Umbraco.Web // IoC setup for LightInject for MVC/WebApi Container.EnableMvc(); - Container.RegisterMvcControllers(PluginManager); + Container.RegisterMvcControllers(PluginManager, GetType().Assembly); container.EnableWebApi(GlobalConfiguration.Configuration); - container.RegisterApiControllers(PluginManager); + container.RegisterApiControllers(PluginManager, GetType().Assembly); } ///