Bugfix - controller injection in Release mode
This commit is contained in:
@@ -14,17 +14,14 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="pluginManager"></param>
|
||||
public static void RegisterMvcControllers(this IServiceRegistry container, PluginManager pluginManager)
|
||||
/// <param name="assembly"></param>
|
||||
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<IController>(specificAssemblies: new[] { Assembly.GetCallingAssembly() });
|
||||
foreach (var type in types)
|
||||
{
|
||||
container.Register(type, new PerRequestLifeTime());
|
||||
}
|
||||
container.RegisterControllers<IController>(pluginManager, assembly);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -32,18 +29,21 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="pluginManager"></param>
|
||||
public static void RegisterApiControllers(this IServiceRegistry container, PluginManager pluginManager)
|
||||
/// <param name="assembly"></param>
|
||||
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<IHttpController>(specificAssemblies: new[] { Assembly.GetCallingAssembly() });
|
||||
foreach (var type in types)
|
||||
{
|
||||
container.Register(type, new PerRequestLifeTime());
|
||||
}
|
||||
container.RegisterControllers<IHttpController>(pluginManager, assembly);
|
||||
}
|
||||
|
||||
private static void RegisterControllers<TController>(this IServiceRegistry container, PluginManager pluginManager, Assembly assembly)
|
||||
{
|
||||
var types = pluginManager.ResolveTypes<TController>(specificAssemblies: new[] { assembly });
|
||||
foreach (var type in types)
|
||||
container.Register(type, new PerRequestLifeTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,20 +128,22 @@ namespace Umbraco.Web.Trees
|
||||
: Attempt<TreeNode>.Succeed(node);
|
||||
}
|
||||
|
||||
internal static Attempt<TreeNodeCollection> TryLoadFromControllerTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, HttpControllerContext controllerContext)
|
||||
internal static Attempt<TreeNodeCollection> TryLoadFromControllerTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, HttpControllerContext controllerContext)
|
||||
{
|
||||
var foundControllerTreeAttempt = appTree.TryGetControllerTree();
|
||||
if (foundControllerTreeAttempt.Success == false)
|
||||
{
|
||||
return Attempt<TreeNodeCollection>.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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user