Prism WPF Templates
Four Visual Studio 2010 templates to support creating Prism applications using MVVM.
The Four templates are:
Prism WPF Application is the starting point for a new application. It combines the other three templates together to create a fully functioning prism application.
These templates are dependent on the following NuGet Packages (all setup when you run the template):
When you run the template, no extra work is needed. All these dependencies are included and setup by the template.
As later versions of these are released, you can use NuGet to get the latest versions. (These dependencies are setup as NuGet packages by the template.)
(The dependency to NSubstitue is explained in the Prism Regions section below.)
The code created by these templates is setup in 3 sections: Prism Regions, Prism Services and the Shell
A prism shell is the part of the application that puts regions onto window(s) as the actual application. No business or UI logic should be done here. Only aggregation of regions and setup of of the IOC (Unity) is appropriate for this project.
A prism region is a modular UI piece. It usually contains one View and one ViewModel. The template will create both of these files. It will also create a Design Folder that contains a DesignViewModel.
The DesignViewModel is where design time data should be placed. Any objects created in this class will not be used at Run Time, but are displayed by the Visual Studio and Expression Blend designers.
The ViewModel inherits from PrismMVVMLibrary's ViewModelBase. ViewModelBase does have aIsInDesignMode variable that can be used to not execute Run Time code at Design Time. But in an effort limit the need to have frequent checks for design mode, PrismMVVMLibrary also has mocked versions ofIUnityContainer, IEventAggregator and IRegionManager. These mocked versions are passed from the DesignViewModel to the actual ViewModel for Design Time execution.
When adding a new region (using the Prism WPF Region template) you will need to copy the commented out xml in the RegionModule.cs file to the Shell's ModuleCatalog.xml file. (And add a reference to the Region project to the Shell project so the dll will get copied to the shell project.)
A prism service is the "Model" part of Model View ViewModel (MVVM). The Prism Service template will create 4 projects.
This is the actual logic of the Prism Service. Frequently this will call out to a Web Service. But it can also just execute business logic.
This should NEVER be referenced by a Region or other service. (Use Unity to inject an instance of the interface.)
Any Classes that are returned from Web Service calls should not be passed out of this project. They should be converted to equivalent Business Objects created in the ServiceProjectObjects project.
When a Prism Service performs an action, it is useful to let the whole app know that the action happened. Prism Events allows for this via the IEventAggregator.
The model these templates follow is that Regions call services -> Services call events -> Regions and/or Services subscribe to events.
A common practice is to make a Region call a Prism Service asynchronously and then catch the complete event to know when the call has finished and what the result was.
Since methods in the ServiceProject should never be called directly, the ServiceProjectIterface project is the place to create the interfaces for that allows for dependency injection of the ServiceProject. (Using unity)
Define Business Objects here.
Data Contracts from Web Service calls should not be used outside of the ServiceProject. This controls the external dependency on those contracts. Client side Business Object should be created and the information in the Data Contract should be transferred into the Business Objects.
Example: If I have a Web Service call that returns aCustomer Data Contract, I would create a Customer Business Object that more or less mirrors theCustomer Data Contract. I would then use AutoMapper copy the data in theCustomer Data Contract into the Customer Business Object. I would then use theCustomer Business Object in the rest of my application.
The image below shows the projects of the Templates create and the dependencies each has when setup by the Prism WPF Application template:
NOTE: There is a BUG in ReSharper (Version 5 only) that causes NuGet dependencies to not be recognized after the template is run. Unloading and reloading the project will allow the depencencies to be seen by ReSharper. The solution will compile and run despite this ReSharper bug. (The error only affects syntax highlighting.)
Versions 6 and 7 do not have this issue.