diff --git a/src/Umbraco.Core/ObjectResolution/MacroFieldEditorsResolver.cs b/src/Umbraco.Core/ObjectResolution/MacroFieldEditorsResolver.cs
index f0b6867a38..6015c14d94 100644
--- a/src/Umbraco.Core/ObjectResolution/MacroFieldEditorsResolver.cs
+++ b/src/Umbraco.Core/ObjectResolution/MacroFieldEditorsResolver.cs
@@ -8,6 +8,8 @@ using umbraco.interfaces;
namespace Umbraco.Core.ObjectResolution
{
+ // FIXME - specific resolvers should not be in Umbraco.Core.ObjectResolution ??
+
///
/// A resolver to return all IMacroGuiRendering objects
///
diff --git a/src/Umbraco.Core/ObjectResolution/ManyObjectsResolverBase.cs b/src/Umbraco.Core/ObjectResolution/ManyObjectsResolverBase.cs
index 9343b1a58b..64d850c66e 100644
--- a/src/Umbraco.Core/ObjectResolution/ManyObjectsResolverBase.cs
+++ b/src/Umbraco.Core/ObjectResolution/ManyObjectsResolverBase.cs
@@ -6,30 +6,37 @@ using System.Web;
namespace Umbraco.Core.ObjectResolution
{
- internal abstract class ManyObjectsResolverBase : ResolverBase
+ ///
+ /// The base class for all many-objects resolvers.
+ ///
+ /// The type of the concrete resolver class.
+ /// The type of the resolved objects.
+ public abstract class ManyObjectsResolverBase : ResolverBase
where TResolved : class
where TResolver : class
{
- private List _applicationInstances = null;
+ private IEnumerable _applicationInstances = null;
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
private readonly List _instanceTypes = new List();
+ private int _defaultPluginWeight = 10;
+
#region Constructors
-
-
+
///
/// Initializes a new instance of the class with an empty list of objects.
///
- /// The lifetime scope of instantiated objects, default is per Application
+ /// The lifetime scope of instantiated objects, default is per Application.
+ /// If is per HttpRequest then there must be a current HttpContext.
+ /// is per HttpRequest but the current HttpContext is null.
protected ManyObjectsResolverBase(ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
{
CanResolveBeforeFrozen = false;
if (scope == ObjectLifetimeScope.HttpRequest)
{
if (HttpContext.Current == null)
- {
throw new InvalidOperationException("Use alternative constructor accepting a HttpContextBase object in order to set the lifetime scope to HttpRequest when HttpContext.Current is null");
- }
+
CurrentHttpContext = new HttpContextWrapper(HttpContext.Current);
}
@@ -38,50 +45,56 @@ namespace Umbraco.Core.ObjectResolution
}
///
- /// Initializes a new instance of the class with an empty list of objects.
+ /// Initializes a new instance of the class with an empty list of objects,
/// with creation of objects based on an HttpRequest lifetime scope.
///
- ///
+ /// The HttpContextBase corresponding to the HttpRequest.
+ /// is null.
protected ManyObjectsResolverBase(HttpContextBase httpContext)
{
CanResolveBeforeFrozen = false;
- if (httpContext == null) throw new ArgumentNullException("httpContext");
+ if (httpContext == null)
+ throw new ArgumentNullException("httpContext");
LifetimeScope = ObjectLifetimeScope.HttpRequest;
CurrentHttpContext = httpContext;
_instanceTypes = new List();
}
///
- /// Initializes a new instance of the class with an initial list of objects.
+ /// Initializes a new instance of the class with an initial list of object types.
///
- /// The list of objects.
- /// If set to true will resolve singleton objects which will be created once for the lifetime of the application
+ /// The list of object types.
+ /// The lifetime scope of instantiated objects, default is per Application.
+ /// If is per HttpRequest then there must be a current HttpContext.
+ /// is per HttpRequest but the current HttpContext is null.
protected ManyObjectsResolverBase(IEnumerable value, ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
: this(scope)
{
- _instanceTypes = new List(value);
+ _instanceTypes = value.ToList();
}
///
- /// Initializes a new instance of the class with an initial list of objects
+ /// Initializes a new instance of the class with an initial list of objects,
/// with creation of objects based on an HttpRequest lifetime scope.
///
- ///
- ///
+ /// The HttpContextBase corresponding to the HttpRequest.
+ /// The list of object types.
+ /// is null.
protected ManyObjectsResolverBase(HttpContextBase httpContext, IEnumerable value)
: this(httpContext)
{
- _instanceTypes = new List(value);
+ _instanceTypes = value.ToList();
}
#endregion
///
- /// used internally for special resolvers to be able to resolve objects before resolution is frozen.
+ /// Gets or sets a value indicating whether the resolver can resolve objects before resolution is frozen.
///
+ /// This is false by default and is used for some special internal resolvers.
internal bool CanResolveBeforeFrozen { get; set; }
///
- /// Returns the list of Types registered that instances will be created from
+ /// Gets the list of types to create instances from.
///
protected virtual IEnumerable InstanceTypes
{
@@ -89,114 +102,144 @@ namespace Umbraco.Core.ObjectResolution
}
///
- /// Returns the Current HttpContextBase used to construct this object if one exists.
- /// If one exists then the LifetimeScope will be ObjectLifetimeScope.HttpRequest
+ /// Gets or sets the used to initialize this object, if any.
///
+ /// If not null, then LifetimeScope will be ObjectLifetimeScope.HttpRequest.
protected HttpContextBase CurrentHttpContext { get; private set; }
///
- /// Returns the ObjectLifetimeScope for created objects
+ /// Gets or sets the lifetime scope of resolved objects.
///
protected ObjectLifetimeScope LifetimeScope { get; private set; }
- private int _defaultPluginWeight = 10;
-
///
- /// Used in conjunction with GetSortedValues and WeightedPluginAttribute, if any of the objects
- /// being resolved do not contain the WeightedPluginAttribute then this will be the default weight applied
- /// to the object.
+ /// Gets the resolved object instances, sorted by weight.
///
+ /// The sorted resolved object instances.
+ ///
+ /// The order is based upon the WeightedPluginAttribute and DefaultPluginWeight.
+ /// Weights are sorted ascendingly (lowest weights come first).
+ ///
+ protected IEnumerable GetSortedValues()
+ {
+ var values = Values.ToList();
+
+ // FIXME - so we're re-sorting each time?
+
+ values.Sort((f1, f2) => GetObjectWeight(f1).CompareTo(GetObjectWeight(f2)));
+ return values;
+ }
+
+ ///
+ /// Gets or sets the default type weight.
+ ///
+ /// Determines the weight of types that do not have a WeightedPluginAttribute set on
+ /// them, when calling GetSortedValues.
protected virtual int DefaultPluginWeight
{
get { return _defaultPluginWeight; }
set { _defaultPluginWeight = value; }
}
- ///
- /// If a resolver requries that objects are resolved with a specific order using the WeightedPluginAttribute
- /// then this method should be used instead of the Values property.
- ///
- ///
- protected IEnumerable GetSortedValues()
+ int GetObjectWeight(object o)
{
- var vals = Values.ToList();
- //ensure they are sorted
- vals.Sort((f1, f2) =>
- {
- Func