The Collectionordermodule class is a AUTOFAC module (module that wraps a series of components and related functions together) rather than a orchard module. The function is to ensure that multiple components registered to the container can be extracted in the Order of FIFO (first in first out). The following examples illustrate:
1. Create Icustomerservice interface: Public interface icustomerservice {} 2. Create two classes that implement the Icustomerservice interface:Public class Defaultcustomerservice : icustomerservice {} /c2>Public class Vipcustomerservice : icustomerservice {} 3. Test:[testfixture] Public class autofactest {[ Test] Public void testcollectionmodule () { containerbuilder builder = new containerbuilder(); //builder. Registermodule (New Collectionordermodule ()); Builder. registertype< defaultcustomerservice> (). as<icustomerservice > (); Builder. registertype< vipcustomerservice> (). as<icustomerservice > (); icontainer container = Builder. Build (); var customeres = container. resolve<IEnumerable< icustomerservice>> (); //judge the first registered service, take out the first one is not Assert. That (customeres. First (), is . typeof<defaultcustomerservice> ()); //Judging the last registered service, take out is not the last one Assert. That (customeres. Last (), is . typeof<vipcustomerservice> ()); //Only affects set resolution, parsing individual service not affected var customer = container. resolve<icustomerservice > (); Assert. That (customer, is .) typeof<vipcustomerservice> ()); } } The above code cannot be tested through.
4. If you register a collectionordermodule with the AUTOFAC container, you will be able to ensure that the test passes: [ Test] Public void testcollectionmodule () { containerbuilder builder = new containerbuilder(); Builder. Registermodule ( newcollectionordermodule ()); //... }attached, the source of Collectionordermodule:class Collectionordermodule : imodule { Public void Configure ( icomponentregistry componentregistry) {componentregistry.registered + = (sender, registered) = { //Only bother watching enumerable resolves var limittype = registered. ComponentRegistration.Activator.LimitType; if (typeof ( IEnumerable). IsAssignableFrom (Limittype)) { registered.ComponentRegistration.Activated + = (Sender2, Activated) + = { //AUTOFAC ' s IEnumerable feature returns an Array if (activated. Instance is Array) { //Orchard needs FIFO, not FILO, component order Array . Reverse ((Array ) activated. Instance); } }; } }; } } The purpose of this orchard is to be further explored. But it is certain that orchard is Order-sensitive for some components.
reference: Autofac:structuring with Modules autofac:activation events Autofac.module
Orchard Source Analysis (4.1): Orchard.Environment.CollectionOrderModule class