Partilhar via


Getting started using Prism for the Windows Runtime

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

From: Developing a Windows Store business app using C#, XAML, and Prism for the Windows Runtime

Previous page | Next page

Learn how to build and run AdventureWorks Shopper, the reference implementation for Prism for the Windows Runtime, and how the source code is organized in Microsoft Visual Studio. The AdventureWorks Shopper reference implementation demonstrates how to accelerate the development of a Windows Store business app by using Prism.

Download

You will learn

  • How to structure the Visual Studio solution for a Windows Store business app that uses the Model-View-ViewModel (MVVM) pattern.

Applies to

  • Windows Runtime for Windows 8.1
  • C#
  • Extensible Application Markup Language (XAML)

Building and running the sample

Build the AdventureWorks Shopper Visual Studio solution as you would build a standard solution.

  1. On the Visual Studio menu bar, choose Build > Build Solution.
  2. After you build the solution, you must deploy it. On the menu bar, choose Build > Deploy Solution. Visual Studio also deploys the project when you run the app from the debugger.
  3. After you deploy the project, you should run it. On the menu bar, choose Debug > Start Debugging. Make sure that AdventureWorks.Shopper is the startup project. When you run the app, the hub page appears.

[Top]

Visual Studio solution structure for a Windows Store business app that uses the MVVM pattern

The AdventureWorks Shopper Visual Studio solution organizes the source code and other resources into projects. All of the projects use Visual Studio solution folders to organize the source code and other resources into categories. The following table outlines the projects that make up the AdventureWorks Shopper reference implementation.

Project Description
AdventureWorks.Shopper This project contains the views for the AdventureWorks Shopper reference implementation, the package manifest, and the App class that defines the startup behavior of the app, along with supporting classes and resources. For more info see The AdventureWorks.Shopper project.
AdventureWorks.UILogic This project contains the business logic for the AdventureWorks Shopper reference implementation, and comprises view models, models, repositories, and service classes. For more info see The AdventureWorks.UILogic project.
AdventureWorks.WebServices This project contains the web service for the AdventureWorks Shopper reference implementation. For more info see The AdventureWorks.WebServices project.
Microsoft.Practices.Prism.PubSubEvents This project contains classes that implement the event aggregator. For more info see The Microsoft.Practices.Prism.PubSubEvents project.
Microsoft.Practices.Prism.StoreApps This project contains interfaces and classes that provide MVVM support with lifecycle management, and core services to the AdventureWorks Shopper reference implementation. For more info see The Microsoft.Practices.Prism.StoreApps project.
AdventureWorks.UILogic.Tests This project contains unit tests for the AdventureWorks.UILogic project.
AdventureWorks.WebServices.Tests This project contains unit tests for the AdventureWorks.WebServices project.
Microsoft.Practices.Prism.PubSubEvents.Tests This project contains unit tests for the Microsoft.Practices.Prism.PubSubEvents project.
Microsoft.Practices.Prism.StoreApps.Tests This project contains unit tests for the Microsoft.Practices.Prism.StoreApps project.

 

You can reuse some of the components in the AdventureWorks Shopper reference implementation in any Windows Store app with little or no modification. For your own app, you can adapt the organization and ideas that these files provide.

The AdventureWorks.Shopper project

The AdventureWorks.Shopper project contains the following folders:

  • The Assets folder contains images for the splash screen, tile, and other Windows Store app required images.
  • The Behaviors folder contains behaviors that are exposed to view classes.
  • The Common folder contains the DependencyPropertyChangedHelper class which monitors a dependency property for changes, and standard styles used by the app.
  • The Controls folder contains the AutoRotatingGridView and MultipleSizedGridView controls.
  • The Converters folder contains data converters such as the BooleanToVisibilityConverter and the NullToVisibleConverter.
  • The DesignViewModels folder contains design-time view model classes that are used to display sample data in the visual designer.
  • The Services folder contains the AlertMessageService and SecondaryTileService classes.
  • The Strings folder contains resource strings used by this project, with subfolders for each supported locale.
  • The Themes folder contains the application styles used by the app.
  • The Views folder contains the pages and flyouts for the app. The app uses a default convention that attempts to locate pages in the "Views" namespace.

The AdventureWorks.UILogic project

The AdventureWorks.UILogic project contains the model, repository, service, and view model classes. Placing the model and view model classes into a separate assembly provides a simple mechanism for ensuring that view models are independent from their corresponding views.

The AdventureWorks.UILogic project contains the following folders:

  • The Models folder contains the entities that are used by view model classes.
  • The Repositories folder contains repository classes that access the web service.
  • The Services folder contains interfaces and classes that implement services that are provided to the app, such as the AccountService and TemporaryFolderCacheService classes.
  • The Strings folder contains resource strings used by this project, with subfolders for each supported locale.
  • The ViewModels folder contains the application logic that is exposed to XAML controls. When a view class is associated with a view model class a default convention is used which will attempt to locate the view model class in the "ViewModels" namespace.

The AdventureWorks.WebServices project

The AdventureWorks.WebServices project is a sample web service that uses an in-memory database to provide data to the AdventureWorks Shopper reference implementation. When the reference implementation is deployed through Visual Studio this web service is deployed locally on the ASP.NET development server.

The AdventureWorks.WebServices project contains the following folders:

  • The App_Start folder contains the configuration logic for the web service.
  • The Controllers folder contains the controller classes used by the web service.
  • The Images folder contains product images.
  • The Models folder contains the entities that are used by the web service. These entities contain the same properties as the entities in the AdventureWorks.UILogic project, with some containing additional validation logic.
  • The Repositories folder contains the repository classes that implement the in-memory database used by the web service.
  • The Strings folder contains a resource file containing strings used by the web service.
  • The Views folder contains the Web.config settings and configuration file for the web service. It does not contain views because it uses the ASP.NET Web API, which returns data rather than displays views.

Note  The AdventureWorks.WebServices project does not provide guidance for building a web service.

 

The Microsoft.Practices.Prism.PubSubEvents project

The Microsoft.Practices.Prism.PubSubEvents project is a Portable Class Library that contains classes that implement event aggregation. You can use this library for communicating between loosely coupled components in your own app. The project has no dependencies on any other projects. For more info about this library, see Prism for the Windows Runtime reference.

The Microsoft.Practices.Prism.StoreApps project

This project contains the reusable infrastructure of the AdventureWorks Shopper reference implementation, which you can use for building your own Windows Store app. It contains classes to build Windows Store apps that support MVVM, navigation, state management, validation, and commands.

The Microsoft.Practices.Prism.StoreApps project uses Visual Studio solution folders to organize the source code and other resources into these categories:

  • The Interfaces folder contains the interfaces that are implemented by classes in this project.
  • The Strings folder contains resource strings used by this project, with subfolders for each supported locale.

For more info about this library, see Prism for the Windows Runtime reference.

[Top]

Where to get more info

For info about the logical architecture of a Windows Store business app that uses Prism, see Architecture of a Windows Store business app that uses Prism. For more info about using Prism see Using Prism to create a Windows Store app. For more info about the tasks that this documentation can help you with, see Developer tasks for building a Windows Store business app.

[Top]