Disclaimer: Prism Novice. I'm reading up furiously to make up for lost time though :)
Context: I need to write automated acceptance tests for a WPF application built using Prism.
Issues: I find that it is convoluted trying to compose the backing ViewModels and everything that they need without the UI.
I may be wrong here... Prism allows you to mark up the shell with named placeholders (regions). Different modules (isolated units) register their Views with the corresponding RegionNames. The Views also have a dependency on the ViewModel (ctor injection) which is injected via MEF/Unity.
- Showing the view
- triggers creation of child views (regionName => View registry)
- triggers creation of child view models (Mef ctor injection).
Composing the app is thus delegated to Prism (or more importantly the View). This seems like a view-first approach. This throws a spanner in the works for starting up the app without the UI ; testing with the UI is a pain.
What I am looking for is a presenter first approach, which composes the entire object (ViewModel and dependencies) graph without the UI.
var viewModel = Someone.ComposeAndGet<ShellViewModel>();
Is it possible with Prism4 by writing apps differently OR is it not supported ?
[Update : Dec 2011]
http://compositewpf.codeplex.com/discussions/283065
Posted on the prism forums to get shed some more light; seems like it is not possible. The recommendation is to use UI tests for acceptance tests. Prism composes UIs ; thereby has a crucial dependency on views.