Technical Challenges

The Stock Trader Reference Implementation (Stock Trader RI) demonstrates how you can address common technical challenges that you face when you build composite applications in Windows Presentation Foundation (WPF) or Rich Interactive Applications (RIAs) in Silverlight. The following table describes the technical challenges that the Stock Trader RI addresses.

Technical challenge

Feature in Stock Trader RI

Example of where feature is demonstrated

Views and composite UI

Regions: The use of regions for placing the views without having to know how the layout is implemented.


Regions defined in the Shell and Position module's Orders view. Position, Watch, Market, and News module initializers adding content to regions.

StockTraderRI\Shell.xaml

StockTraderRI.Modules.Position\Orders\OrdersView.xaml

StockTraderRI.Modules.Position\PositionModule.cs

StockTraderRI.Modules.Position\Controllers\OrdersController.cs

StockTraderRI.Modules.Watch\WatchModule.cs

StockTraderRI.Modules.Market\MarketModule.cs

StockTraderRI.Modules.News\Controllers\NewsController.cs

Composite view: Shows how a composite view communicates with its child view.

Order screen

StockTraderRI.Modules.Position\Orders\OrderCompositePresentationModel.cs

StockTraderRI.Modules.Position\Orders\OrderDetailsPresentationModel.cs

StockTraderRI.Modules.Position\Orders\OrderCommandsView.xaml.cs

StockTraderRI.Modules.Position\Controllers\OrdersController.cs

Compose UI across modules: Shows how a module can have views in different parts of the shell that interact with each other.

The Watch module has a view and also is a part of the toolbar.

StockTraderRI.Modules.Watch\AddWatch\AddWatchView.xaml

StockTraderRI.Modules.Watch\WatchList\WatchListView.xaml

The News module has an article list view and a popup article reader view that show the same articles.

StockTraderRI.Modules.News\Article\ArticleView.xaml

StockTraderRI.Modules.News\Article\NewsReader.xaml

Decoupled communication

Commands: Shows the Command pattern. The command to buy or sell a stock is a delegate command. Each row in the list uses the same command instance but with a different parameter corresponding to the stock. This decouples the invoker from the receiver and shows passing additional data with the command.

Buy and Sell command invokers in PositionSummaryView and handlers in OrdersController

StockTraderRI.Modules.Position\Controllers\OrdersController.cs

StockTraderRI.Modules.Position\PositionSummary\PositionSummaryView.xaml



Composite commands: Use composite commands to broadcast all of the commands. The Submit All or Cancel All commands execute all of the individual instances of the Submit or Cancel commands.

Submit All and Cancel All buttons

StockTraderRI.Infrastructure\StockTraderRICommands.cs

StockTraderRI.Modules.Position\Orders\OrderDetailsPresentationModel.cs

StockTraderRI.Modules.Position\Controllers\OrdersController.cs

Event Aggregator pattern: Publish and Subscribe to events across decoupled modules. Publisher and Subscriber have no contract other than the event type.

Show relevant news content: When the user selects a position in the position list, the communication to the news module uses the EventAggregator service.

StockTraderRI.Modules.Position\PositionSummary\PositionSummaryPresentationModel.cs

StockTraderRI.Modules.News\Controllers\NewsController.cs

Market feed updates: The consumers of the market feed service subscribe to an event to be notified when new feeds are available and the consumers then update the model behind the UI.

StockTraderRI.Modules.Market\Services\MarketFeedService.cs

StockTraderRI.Modules.Position\PositionSummary\ObservablePosition.cs

StockTraderRI.Modules.Watch\WatchList\WatchListPresentationModel.cs

Services: Services are also used to communicate between modules. Services are more contractual and flexible than commands.

Several service implementations in module assemblies

Services:

StockTraderRI.Modules.Market\Services\MarketFeedService.cs

StockTraderRI.Modules.Market\Services\MarketHistoryService.cs

StockTraderRI.Modules.News\Services\NewsFeedService.cs

StockTraderRI.Modules.Watch\Services\WatchListService.cs

StockTraderRI.Modules.Position\Services\AccountPositionService.cs

StockTraderRI.Modules.Position\Services\XmlOrdersService.cs

Multi-targeting WPF and Silverlight

Code sharing

Almost every class (excluding views in Silverlight) is a link to a file that exists in the Desktop version.

The StockTraderRI solution includes a Desktop version and Silverlight version.

Some classes are defined as partial to add a Desktop-only or Silverlight-only implementation of certain pieces.

StockTraderRI.Modules.Position.Silverlight\Orders\OrdersPresentationModel.Silverlight.cs

StockTraderRI\StockTranderRIBootstrapper.Desktop.cs

Usage of #if SILVERLIGHT to branch small pieces of code that target Desktop-only or Silverlight-only.

StockTraderRI.Infrastructure\Behaviors\RegionPopupBehaviors.cs

Several Test Fixture classes.

Usage of Project Linker to create links to files in the Desktop projects.

If Project Linker is installed in the user's environment, files that are added, removed, or renamed from the Desktop version of the RI will be reflected in the Silverlight projects.

Other technical challenges

WPF: Use WPF for the user interface

Shell and Module views

The starting point for Stock Trader RI - Desktop version is in the StockTraderRI\App.xaml.cs

Silverlight: Use Silverlight for the user interface

Shell and Module views

The starting point for Stock Trader RI - Silverlight version is in the StockTraderRI.Silverlight\App.xaml.cs

Bootstrapper: The use of a bootstrapper to initialize the application with global services.

Created bootstrapper with the Unity DI container and configuring global services, such as logging and defining the module catalog.

Bootstrapper:

StockTraderRI\StockTraderRIBootstrapper.cs

For information about the main elements of the Stock Trader RI, see How the Stock Trader RI Works. To run the Stock Trader RI, see Installing and Running.

Home page on MSDN | Community site