Merge pull request #6331 from umbraco/v7/bugfix/6024-app-event-handler-weight
Fixes ApplicationEventHandler default weight of -100 not set on Umbraco.Web ApplicationEventHandlers #6024
This commit is contained in:
@@ -89,16 +89,20 @@ namespace Umbraco.Core.ObjectResolution
|
||||
}
|
||||
}
|
||||
|
||||
protected override int GetObjectWeight(object o)
|
||||
{
|
||||
protected override int GetObjectWeight(object o) => GetObjectWeightInternal(o, DefaultPluginWeight);
|
||||
|
||||
internal static int GetObjectWeightInternal(object o, int defaultPluginWeight)
|
||||
{
|
||||
var type = o.GetType();
|
||||
var attr = type.GetCustomAttribute<WeightAttribute>(true);
|
||||
if (attr != null) return attr.Weight;
|
||||
var name = type.Assembly.FullName;
|
||||
|
||||
// we should really attribute all our Core handlers, so this is temp
|
||||
var core = name.InvariantStartsWith("Umbraco.") || name.InvariantStartsWith("Concorde.");
|
||||
return core ? -DefaultPluginWeight : DefaultPluginWeight;
|
||||
var core = name.InvariantStartsWith("umbraco,") // This handles the umbraco.dll (Umbraco.Web) project
|
||||
|| name.InvariantStartsWith("Umbraco.") // This handles all other Umbraco.* assemblies - in the case of v7, this is ONLY Umbraco.Core
|
||||
|| name.InvariantStartsWith("Concorde."); // Special case for Cloud assemblies
|
||||
return core ? -defaultPluginWeight : defaultPluginWeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -202,4 +206,4 @@ namespace Umbraco.Core.ObjectResolution
|
||||
_orderedAndFiltered = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using NUnit.Framework;
|
||||
using umbraco.BusinessLogic;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Tests.Resolvers
|
||||
{
|
||||
[TestFixture]
|
||||
public class ApplicationEventsResolverTests
|
||||
{
|
||||
[Test]
|
||||
public void Core_Event_Handler_Weight_Test()
|
||||
{
|
||||
//from the 'umbraco' (Umbraco.Web) assembly
|
||||
Assert.AreEqual(-100, ApplicationEventsResolver.GetObjectWeightInternal(new GridPropertyEditor(), 100));
|
||||
//from the 'Umbraco.Core' assembly
|
||||
Assert.AreEqual(-100, ApplicationEventsResolver.GetObjectWeightInternal(new IdentityModelMappings(), 100));
|
||||
//from the 'Umbraco.Test' assembly
|
||||
Assert.AreEqual(-100, ApplicationEventsResolver.GetObjectWeightInternal(new MyTestEventHandler(), 100));
|
||||
|
||||
//from the 'umbraco.BusinessLogic' assembly - which we are not checking for and not setting as the negative of the default
|
||||
Assert.AreEqual(100, ApplicationEventsResolver.GetObjectWeightInternal(new ApplicationRegistrar(), 100));
|
||||
}
|
||||
|
||||
private class MyTestEventHandler : ApplicationEventHandler
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,9 @@ using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Tests.Resolvers
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
|
||||
[TestFixture]
|
||||
public class LazyManyObjectResolverTests
|
||||
{
|
||||
|
||||
@@ -191,4 +193,4 @@ namespace Umbraco.Tests.Resolvers
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,6 +197,7 @@
|
||||
<Compile Include="Packaging\PackageExtractionTests.cs" />
|
||||
<Compile Include="Persistence\Repositories\SimilarNodeNameTests.cs" />
|
||||
<Compile Include="PublishedContent\StronglyTypedModels\Home.cs" />
|
||||
<Compile Include="Resolvers\ApplicationEventsResolverTests.cs" />
|
||||
<Compile Include="Services\AuditServiceTests.cs" />
|
||||
<Compile Include="Services\ConsentServiceTests.cs" />
|
||||
<Compile Include="Services\MemberGroupServiceTests.cs" />
|
||||
|
||||
Reference in New Issue
Block a user