What is the order of the service call

Topics: Prism v4 - WPF 4
Aug 5, 2011 at 3:25 PM


I'm tring to understand StockTraderRI execution sequence. Here are a couple of questions.

1. One of my understanding is the order of the modules are being called are in ConfigureAggregateCatalog(), is this correct?

2. Is StockTraderRICommands  serverve as an entry point to Infrastructure (like the disscusion and that's why it need to be specificlly added in ConfigureAggregateCatalog?

3. What controls the order of all the services being called? When it is needed or as long as it is decorated with "Export" attribute? For example, PositionSummaryViewModel need to inject "IOrdersController", when this "IOrderController" becomes available to be injected?

4. In ConfigureAggregateCatalog(), adding MarkeModule is still necessary even if the MarkeModule is empty and all the type and services in MarkeModule needed to be injected have "Export" attribute?


Aug 5, 2011 at 5:46 PM
Edited Aug 5, 2011 at 5:49 PM


I'll answer your concerns by parts:

1. By design, the load order of the modules that are marked to be loaded when available (such as the modules in the Stock Trader Reference Implementation) should not influence the functionality exposed by them. Therefore, while the order in which their assemblies are added to the aggregate catalog is the one specified in that method, you should not rely on that for the design of your application, and it's not guaranteed that it will be the order in which the initialization of your modules is performed.

2. In the ConfigureAggregateCatalog method inside the StockTraderRIBootstrapper, AssemblyCatalogs are added to the AggregateCatalog, which are formed by Assemblies (that is, instances of the System.Reflection.Assembly class). In order to obtain a reference to that class, you need to refer to the Assembly property of the type of a class that belongs to that assembly. Therefore, since the StockTraderRICommands class belongs to the StockTraderRI.Infrastructure project, the expression


will return the System.Reflection.Assembly corresponding to the StockTraderRI.Infrastructure project.

3. The container internally controls the order of the exports that other exports need as dependencies, so as long as you decorate the necessary parts with the Export attribute, and you don't have circular references, the parts (such as shared services) are likely to be imported correctly.

4. As explained in the second answer, adding the assembly that contains the MarketModule (which is done through obtaining the System.Reflection.Assembly associated to any of the elements of that assembly, in this case the empty MarketModule class) makes all the views and services declared in that assembly to be exported into the MEF container. Therefore, even though no initialization logic is needed (and thus, the MarketModule class is left empty), you need to add that assembly to the aggregate catalog.

I hope you find this helpful.

Guido Leandro Maliandi