Building applications from scratch starting from a blank page or screen in Visual Studio is a frustrating, time consuming and intimidating task. Instead, most developers like to start with a working application that they can modify, tweak and extend to suit their needs.
Far too often though, developers take a demo or a sample as the starting point for their application, and this often leads to a poor application design that’s complex, difficult to test and debug, and inflexible. Demos and samples have their place of course – they are great for illustrating a single concept or a cool new feature – but they are typically not designed to provide a solid base for an entire application.
Prism is a library of design patterns that work together to provide a solid architectural foundation on which you can build real-world Silverlight and WPF applications that are flexible and maintainable. Some of the patterns that Prism contains are fairly simple while others are more complex, but they are designed to work together to solve some of the challenges you face when building these real-world applications.
We illustrate individual patterns using what we call ‘Quick-Starts’ which are small focused sample applications. We illustrate how the patterns work together using what we call a ‘Reference Implementation’, which is a large sample application that implements a real-world scenario (during development, we actually use the RI to help us figure out what challenges a developer faces when building a non-trivial real-world application, and from those challenges we distil the patterns that help to address them and then implement those patterns in a reusable library). For Prism, the RI is a Stock Trader application that allows you buy and sell stocks and to manage your portfolio.
However, neither the Quick-Starts nor the Reference Implementation that we include in Prism are great for taking as a starting point for a new Prism application. The Quick-Starts are too fine-grained and focused on one specific pattern or technique, while the Reference Implementation is too coarse-grained and includes a lot of application logic that’s specific to the stock trader scenario.
To help with this problem, we are considering building a number of solution and project templates for Visual Studio that would give you a simple working app that you could tweak and modify. These would fall somewhere in-between the Quick-Starts and Reference Implementation and provide a basic solution and project structure into which you could add your application specific files.
I spent a couple of days this week prototyping this approach. I built a couple of project templates (one for a Prism Shell, and one for a Prism Module) and a solution template that provide a complete multi-module working app. You can download these templates from here. Together, these templates make up what I call the ‘Prism Quick Start Kit’.
Installation of the project templates is fairly straightforward:
To see the project templates in action, follow these steps:
<prism:ModuleInfo Ref="Prism.Module1.xap"
ModuleName="Module1"
ModuleType="Prism.Module1.ModuleInit, Prism.Module1, Version=1.0.0.0"
InitializationMode="WhenAvailable"/>
I find the project templates described above pretty useful for creating new Prism projects, but there are way too many steps involved to make it a simple and clean experience. What I’d really like to do is to create a ‘Solution Template’ that includes all of the sub-projects and references all linked up and ready to go.
Unfortunately Visual Studio doesn’t by itself allow this to be done easily. There are additional tools and frameworks available that enable this, but at this stage I wanted to keep it simple so the next best thing was to just create a baseline sample project that I can manually copy and modify whenever I want to build a Prism multi-module solution. I call this the ‘Prism Quick-Start Solution’.
The baseline quick-start solution is the third zip file in the Prism quick-start kit. If you unzip it you’ll see that it contains Web and Shell projects, two Module projects and a ‘Common’ class library. The solution has all of these linked together and includes the Prism and Unity assembly so that you don’t have to fix up any references. In other words, you can unzip it and go!
If you run the app or examine the code, you’ll see that it contains a little more functionality than you get by just using the project templates described above. This is because, in a typical Prism application, there are a couple of common things that you need to do to coordinate the functionality between the Shell and the multiple Modules.
An example of this is when you implement loosely-coupled events between modules to coordinate context or user actions. The quick-start solution shows how to implement simple cross-module master-detail functionality – when you click on the Master View (from Module 1), the Catalog View (from Module 2) will update. This also shows how you typically coordinate data and context across two modules…
Another example is the use of a Controller class to programmatically coordinate the display of Views in a region in order to implement navigation or application workflow. The quick-start solution uses a controller class to programmatically display views in the main region when the user clicks on buttons in the master view.
The quick-start solution is meant to provide a basic structure for a Prism app and to include the most commonly used features of Prism. I find it very useful as a starting point because it contains all of the little code snippets and that you often need and has a basic structure in place making it pretty straightforward to take it and modify it to create many different types of applications. It’s hopefully also a good place to experiment with Prism and to learn about some of its basic features.
oO------Oo
I hope you find these templates useful. We’re hoping to provide templates like these in Prism 3.0 but we’d also like to provide item templates, code snippets and some simple in-tool automation to make building Prism apps really simple and straightforward. Let me know what you think, and whatever else you’d like to see in Prism 3.0…
Download the Prism Quick Start Kit here.
PingBack from http://asp-net-hosting.simplynetdev.com/prism-quick-start-kit/
Thank you for submitting this cool story - Trackback from DotNetShoutout
9efish.感谢你的文章 - Trackback from 9eFish
Excellent David !!!
All I have to do is replace the DataItemListBox with a Silverlight Treeview in the Master View and I have the start of an entry level dashboard solution!
Until this 'kit', I couldn't close the gap between overwhelming detail and simplistic, here is a container, here is a module intro idea.
Cric mork's excellent tutorial gave me enough background, along with excellent P&P docs, to be able to slide right into your example.
Your quickstart gives a sufficient and necessary arrangement of folders from controllers to views, behind which I can begin to develop services to breath some life into the sample views you've provided.
A very useful starting block! The fun begins!
With great appreciation,
Greg Hazzard
Is this any good for desktop apps or web only? I'm currently basing my solution on the Prism RI, but would prefer a cleaner starting point.
Thank you for submitting this cool story - Trackback from progg.ru
#.think.in infoDose #31 (24th May - 1st June)
Looks like there is no Desktop quick start yet, it's Silverlight only. :(
How can you use a custom font in the App Banner? I tried setting FontFamily="MINYN___.TTF#Minya Nouvelle". The font shows up in the VS Preview, but not when I run the app.
@Ozzy1873 - Hmmm, It might be that Silverlight can’t locate the .ttf file on the server. Do you have the “MINYN___.TTF” file in the ClientBin folder along with the xaps? It may also be the underscores in the filenam that are causing problems. This might help too: http://timheuer.com/blog/archive/2008/03/10/embedding-fonts-in-silverlight-2.aspx.
@GraemeF - I'm working on a WPF desktop version of this and I'll post it here in a few days.
I cant open the Prism Quick Start Solution with Visual Studio Express 2008.
thanks
I would like to see Prism work with .NET RIA Services. These two would make a perfect match from patterns and practices.
cheers
I'm getting 'The project type is not supported by this installation.' whenever I try to open the QuickStartSolution in Visual Studio Professional.
@gsegree - The Silverlight projects can only be opened if you have the Silverlight tools for Visual Studio installed. Can you check to make sure that you can create and run a vanilla Silverlight project?
@mcsean - I am currently working on a post that covers the use of .NET Ria Services and Prism. Watch this space for more news soon.
Thanks for doing this - it's a huge time saver.