Rename WeightAttribute, change default to 100, cleanup

This commit is contained in:
Stephan
2016-11-24 18:13:05 +01:00
parent ed37b84b3b
commit 0179540023
9 changed files with 15 additions and 44 deletions

View File

@@ -15,7 +15,6 @@ namespace Umbraco.Core.ObjectResolution
/// </remarks>
public sealed class ApplicationEventsResolver : ManyObjectsResolverBase<ApplicationEventsResolver, IApplicationEventHandler>, IDisposable
{
private readonly LegacyStartupHandlerResolver _legacyResolver;
/// <summary>
@@ -23,7 +22,7 @@ namespace Umbraco.Core.ObjectResolution
/// </summary>
/// <param name="logger"></param>
/// <param name="applicationEventHandlers"></param>
/// <param name="serviceProvider"></param>
/// <param name="serviceProvider"></param>
internal ApplicationEventsResolver(IServiceProvider serviceProvider, ILogger logger, IEnumerable<Type> applicationEventHandlers)
: base(serviceProvider, logger, applicationEventHandlers)
{
@@ -34,7 +33,7 @@ namespace Umbraco.Core.ObjectResolution
}
/// <summary>
/// Override in order to only return types of IApplicationEventHandler and above,
/// Override in order to only return types of IApplicationEventHandler and above,
/// do not include the legacy types of IApplicationStartupHandler
/// </summary>
protected override IEnumerable<Type> InstanceTypes
@@ -69,7 +68,7 @@ namespace Umbraco.Core.ObjectResolution
var handler = CollectionResolved;
if (handler != null) handler(this, e);
}
/// <summary>
/// Create instances of all of the legacy startup handlers
/// </summary>
@@ -82,11 +81,11 @@ namespace Umbraco.Core.ObjectResolution
protected override bool SupportsClear
{
get { return false; }
}
}
protected override bool SupportsInsert
{
get { return false; }
get { return false; }
}
private class LegacyStartupHandlerResolver : ManyObjectsResolverBase<ApplicationEventsResolver, IApplicationStartupHandler>, IDisposable
@@ -171,9 +170,6 @@ namespace Umbraco.Core.ObjectResolution
//Clear event handlers
CollectionResolved = null;
}
}
}

View File

@@ -17,7 +17,7 @@ namespace Umbraco.Core.ObjectResolution
/// for when there is some processing overhead (i.e. Type finding in assemblies) to return the Types used to instantiate the instances.
/// In some these cases we don't want to have to type-find during application startup, only when we need to resolve the instances.</para>
/// <para>Important notes about this resolver: it does not support Insert or Remove and therefore does not support any ordering unless
/// the types are marked with the WeightedPluginAttribute.</para>
/// the types are marked with the WeightAttribute.</para>
/// </remarks>
public abstract class LazyManyObjectsResolverBase<TResolver, TResolved> : ManyObjectsResolverBase<TResolver, TResolved>
where TResolved : class

View File

@@ -23,7 +23,7 @@ namespace Umbraco.Core.ObjectResolution
private readonly List<Type> _instanceTypes = new List<Type>();
private IEnumerable<TResolved> _sortedValues;
private int _defaultPluginWeight = 10;
private int _defaultPluginWeight = 100;
#region Constructors
@@ -179,7 +179,7 @@ namespace Umbraco.Core.ObjectResolution
/// </summary>
/// <returns>The sorted resolved object instances.</returns>
/// <remarks>
/// <para>The order is based upon the <c>WeightedPluginAttribute</c> and <c>DefaultPluginWeight</c>.</para>
/// <para>The order is based upon the <c>WeightAttribute</c> and <c>DefaultPluginWeight</c>.</para>
/// <para>Weights are sorted ascendingly (lowest weights come first).</para>
/// </remarks>
protected IEnumerable<TResolved> GetSortedValues()
@@ -196,7 +196,7 @@ namespace Umbraco.Core.ObjectResolution
/// <summary>
/// Gets or sets the default type weight.
/// </summary>
/// <remarks>Determines the weight of types that do not have a <c>WeightedPluginAttribute</c> set on
/// <remarks>Determines the weight of types that do not have a <c>WeightAttribute</c> set on
/// them, when calling <c>GetSortedValues</c>.</remarks>
protected virtual int DefaultPluginWeight
{
@@ -212,7 +212,7 @@ namespace Umbraco.Core.ObjectResolution
protected virtual int GetObjectWeight(object o)
{
var type = o.GetType();
var attr = type.GetCustomAttribute<WeightedPluginAttribute>(true);
var attr = type.GetCustomAttribute<WeightAttribute>(true);
return attr == null ? DefaultPluginWeight : attr.Weight;
}

View File

@@ -1,25 +0,0 @@
using System;
namespace Umbraco.Core.ObjectResolution
{
/// <summary>
/// Indicates the relative weight of a resolved object type.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class WeightedPluginAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="WeightedPluginAttribute"/> class with a weight.
/// </summary>
/// <param name="weight">The object type weight.</param>
public WeightedPluginAttribute(int weight)
{
Weight = weight;
}
/// <summary>
/// Gets or sets the weight of the object type.
/// </summary>
public int Weight { get; private set; }
}
}