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:
Louis DeJardin
2011-05-24 15:52:15 -07:00
parent 3e74f4a4d6
commit 80bfa368c1
3 changed files with 25 additions and 0 deletions

View 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);
}
};
}
};
}
}
}

View File

@@ -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());

View File

@@ -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" />