Why is the module responsible for assigning it's view to a region

Topics: Prism v2 - Silverlight 2, Prism v2 - WPF 3.5
Feb 26, 2009 at 6:33 PM
I'm not sure I understand why the module assigns it's view to a region. It seems like you would develop a module to be reusable.

I have a module that I want to use throughout multiple projects and it may appear more than once in a particular shell. I don't see a way to do this currently. Having a module depend upon a region name seems strange. Why can't the shell be responsible for attaching instances of modules to various regions?
Feb 28, 2009 at 4:16 PM
I may be missing what you are saying. However modules do not have to assign views to regions and in my application they never do.  I have several views that are displayed in my main region in one place and in our dialog region it other places. I have a ViewManager object with a method called PresentView(RegionEnum region, IPresentationModel presentationModel); This give the developer the control over what view he/she wants to display as well as in what region. Hope that helps.

Brette
Mar 2, 2009 at 4:29 AM
Hi Brette,

Brett could you provide a little bit more information about you ViewManager:

1. Can u share its source?
2. Module presentation model are usually isolated in module assembly. So u are sharing its interface in Infrastructure?

Thanks,
Alexey Zakharov
Mar 4, 2009 at 3:39 PM
Hi Mike,

It al depends on your goals for applying modularity.

Usually, the goal of modularity is to make modules loosely coupled from other modules. That doesn't make them reusable per se.

You have to put your visual composition somewhere. One approach is to put it in the modules and let them do the composition and we feel this is the most common approach. An other approach is to give this responsibility to the shell (kind of breaks composition, because the shell has to know at least something about your views) or to a seperate composition module or component. You can even decide you want really dynamic composition and have a composition engine (that reads the composition from a config file). However, we're not providing you with one.

In Prism we are supporting two composition models: View Injection and View discovery. 

  • In View Injection, you find a region and add instances of your views to it. This usually is done by your models, because they are the only ones who know about your modules. 
  • In View Discovery, you register the type of a view against a region name.

You can approach view discovery in two ways. If you have defined several views in your shell, then you can say in your modules: Make sure that these views will be added to these regions.

HOWEVER, you can also approach it from a different perspective. You can register your views under a name. For example, if you have a CustomerView, you can register it under the "CustomerView" name. Now if you want to show that view somewhere (for example in the shell or in a different module), simply show a region with that name, and the view will appear.

Hope this helps,
Erwin

 

 

Mar 4, 2009 at 8:55 PM
Edited Mar 4, 2009 at 8:55 PM
Lexer,

I have a interface in my Infrustructure project called IPresentable that has a method called Present(). All my moudle presentation models implement this interface. My method ViewManager.PresentView(IPresentable, Region region) then calls that method. Basically all presentation models that want to leverage my view manager must implement this interface. And this interface exists in my Inf project.
Hope that helps.