Exercise 2: Verification

In this verification, you will run the application to verify that all the queries are shown in the main application. In addition, you will verify the lazy behavior of the query objects.

  1. In order to verify the lazy instantiation of an object you will add an empty constructor to any of the ICarQuery implementations and set a breakpoint on it to check when it is being instantiated. To do this, open the FabrikamQuery.cs (C#) or FabrikamQuery.vb (Visual Basic), add a new constructor to it and set a breakpoint by pressing F9 as shown in the following screenshot.

    Figure 1

    FabrikamQuery constructor breakpoint (C#)

    Figure 2

    FabrikamQuery constructor breakpoint (C#)

  2. Compile the solution (CTRL+SHIFT+B).
  3. Set ContosoAutomotive as the startup project. In the Solution Explorer, right-click ContosoAutomotive and select Set as startup project.
  4. Press F5 to run the application. The parent CashMaker window should appear with a list of manufacturers on it. You should note the FabrikamQuery constructor has not been executed.

    Figure 3

    The CashMaker window shows manufacturers.

  5. Click on the Fabrikam Motor Company icon on the list of manufacturers in the Cash Maker application. Now, the code will stop in the breakpoint you have set in the FabrikamQuery constructor, because the instance is being created on demand.

    Figure 4

    FabrikamQuery constructor breakpoint (C#)

    Figure 5

    FabrikamQuery constructor breakpoint (C#)

  6. Click the close button () in the top right of the Cash Maker window to close it.
  7. Remove the breakpoint and the constructor you just created in the FabrikamQuery class.

Next Step

Exercise 3: Using MEF and Silverlight 4