Orchard Source Analysis (4.1): Orchard.Environment.CollectionOrderModule class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.