Changed how surface controllers are routed: because we don't load plugins in via App_Plugins/[PackageName] like we did in v5 which meant that we can autoroute all plugin controllers with their own areas, in v4 we have to do something different.

Instead (because we still want areas), we have an attribute called PluginControllerAttribute which allows a dev to assign an area name as a string. A package developer should always ensure that all of their plugin controllers are assigned to the same
area. This also lets us get rid of the GUID id part of the plugin (hopefully we can leave it out, just need to run some tests). Since we have areas, package devs can then put their views into
their own folders and not clutter up the local devs ~/Views folder. Perhaps we use App_Plugins/[PackageName] for the views like we did in v5 but need to ask on the mail list. Otherwise it will be the standard MVC:
~/Areas/[AreaName]/Views which will still also clutter up the local devs view folder if they are using Areas.
This commit is contained in:
Shannon Deminick
2012-09-26 11:04:07 +07:00
parent 7b7e3b82f1
commit 332b42aa49
12 changed files with 224 additions and 159 deletions

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Concurrent;
using System.Web.Mvc;
using Umbraco.Core;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// A base class for all plugin controllers to inherit from
/// </summary>
public abstract class PluginController : Controller, IRequiresUmbracoContext
{
/// <summary>
/// stores the metadata about plugin controllers
/// </summary>
private static readonly ConcurrentDictionary<Type, PluginControllerMetadata> Metadata = new ConcurrentDictionary<Type, PluginControllerMetadata>();
/// <summary>
/// Default constructor
/// </summary>
/// <param name="umbracoContext"></param>
protected PluginController(UmbracoContext umbracoContext)
{
UmbracoContext = umbracoContext;
InstanceId = Guid.NewGuid();
}
/// <summary>
/// Useful for debugging
/// </summary>
internal Guid InstanceId { get; private set; }
public UmbracoContext UmbracoContext { get; set; }
/// <summary>
/// Returns the metadata for this instance
/// </summary>
internal PluginControllerMetadata GetMetadata()
{
PluginControllerMetadata meta;
if (Metadata.TryGetValue(this.GetType(), out meta))
{
return meta;
}
var attribute = this.GetType().GetCustomAttribute<PluginControllerAttribute>(false);
meta = new PluginControllerMetadata()
{
AreaName = attribute == null ? null : attribute.AreaName,
ControllerName = ControllerExtensions.GetControllerName(this.GetType()),
ControllerNamespace = this.GetType().Namespace,
ControllerType = this.GetType()
};
Metadata.TryAdd(this.GetType(), meta);
return meta;
}
}
}