mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Reversing order of IEnumerable<TService> resolved from IoC
Components are registered in dependency/priority order and this is also the order events and hooks should fire. The default order of Autofac is opposite what we need for enumerable services. The behavior of resolving a single TService is unchanged - the last-registered of TService is the only returned. --HG-- branch : 1.x extra : transplant_source : %87%22%FC%84%A1%0FP%3C%20w%B4%1EQ%CC%90%20%97%C1%EC%BF
This commit is contained in:
23
src/Orchard/Environment/CollectionOrderModule.cs
Normal file
23
src/Orchard/Environment/CollectionOrderModule.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Autofac.Core;
|
||||
|
||||
namespace Orchard.Environment {
|
||||
internal class CollectionOrderModule : IModule {
|
||||
public void Configure(IComponentRegistry componentRegistry) {
|
||||
componentRegistry.Registered += (s, e) => {
|
||||
// only bother watching enumerable resolves
|
||||
var limitType = e.ComponentRegistration.Activator.LimitType;
|
||||
if (typeof(IEnumerable).IsAssignableFrom(limitType)) {
|
||||
e.ComponentRegistration.Activated += (s2, e2) => {
|
||||
// Autofac's IEnumerable feature returns an Array
|
||||
if (e2.Instance is Array) {
|
||||
// Orchard needs FIFO, not FILO, component order
|
||||
Array.Reverse((Array)e2.Instance);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ namespace Orchard.Environment {
|
||||
public static class OrchardStarter {
|
||||
public static IContainer CreateHostContainer(Action<ContainerBuilder> registrations) {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterModule(new CollectionOrderModule());
|
||||
builder.RegisterModule(new LoggingModule());
|
||||
builder.RegisterModule(new EventsModule());
|
||||
builder.RegisterModule(new CacheModule());
|
||||
|
||||
@@ -173,6 +173,7 @@
|
||||
<Compile Include="DisplayManagement\Implementation\IShapeDisplayEvents.cs" />
|
||||
<Compile Include="DisplayManagement\Implementation\IShapeFactoryEvents.cs" />
|
||||
<Compile Include="DisplayManagement\Shapes\ITagBuilderFactory.cs" />
|
||||
<Compile Include="Environment\CollectionOrderModule.cs" />
|
||||
<Compile Include="Environment\Extensions\OrchardSuppressDependencyAttribute.cs" />
|
||||
<Compile Include="Environment\Features\IFeatureManager.cs" />
|
||||
<Compile Include="Environment\IAssemblyNameResolver.cs" />
|
||||
|
||||
Reference in New Issue
Block a user