Number of views per module and best practices?

Topics: Prism v4 - WPF 4
Jun 24, 2014 at 7:32 AM
Edited Jun 24, 2014 at 7:34 AM
Hi,

In order to break functionality in modules, there are two approaches which I am considering -

A) A module can have more than one MainView and based on certain rule I may load specific view. In this case Initialize() method will have if..else construct to decide which of the MainView needs to be created and loaded in the specific region.

Module - Having two views : AddFundView , ActivityView
        public void Initialize()
        {
            if (ShowFundView)
            {
                var addFundView = Container.Resolve<AddFundView>();
                RegionManager.Regions[Region.Name].Add(addFundView);
            }
            else if (ShowActivityView)
            {
                var activityView = Container.Resolve<ActivityView>();
                RegionManager.Regions[Region.Name].Add(activityView);
            }
        }
A)To have one MainView per module. In module initialize resolve this MainView and add it to appropriate region. In this case I would have two modules, Module1 and Module2

Module 1 - AddFundView
        public void Initialize()
        {
            var addFundView = Container.Resolve<AddFundView>();
            RegionManager.Regions[Region.Name].Add(addFundView);
        }
Module 2 - ActivityView
        public void Initialize()
        {
            var activityView = Container.Resolve<ActivityView>();
            RegionManager.Regions[Region.Name].Add(activityView );
        }
Which of the approach should I follow to organize my Module and View ? Is it best practice to have if..else construct in Module initialization to load specific view?

Thanks
Santosh
Jun 25, 2014 at 9:41 AM
Hello,

Did you managed to find out solution because I am actually in same reflection as you.

IN my scenario I will have a WPF application with mainly 3 mains screen that will be accessible like a Panorama view in the sense that :
Screen 1 will be shown first
Then Screen 2 will be visible when user will slide screen 1 to left
Then Screen 3 will be visible when user will slide screen 2 to left

My screens are identified as follow :

Screen 1 = Product Selection screen
Screen 2 = Selected product information
Screen 3 = Payement screen

In each of those screen, I will have different different region that will identify the Interface as :
  • A header Region => display screen title or other stuff
  • A Center region = > represent main content View which can be based on different Views
  • A command region = > represent screen action buttons
So based on what I have understood I was planning to build a Module for each region.
Then if my Center region is based on multiple View to build the User Interface my idea was to define a single Module for that CenterRegion but which will have the main View containg only ContentControls for each sub view

Then in my code logic, based on condition I will set the Content property of corresponding ContentControl to inject my UserControl which will form my sub view

Does this make sense ?

First time I need to play with Prism and Composit UI so was wondering also

regards
serge
Jun 25, 2014 at 5:37 PM
Edited Jun 25, 2014 at 5:42 PM
Hi,
There may be two approches for center region-

1- For every functionality/screen define one Module having only one View which will be added to your center region. Based on action command you load other module which in turn will create respective view and place it in appropriate region. While doing so you may set RegionContext value which you may want to pass to next screen or you may use event aggregator.

2-Define only one module having three different views. And then use view-switching by using navigation mechanism. Using this way you may also pass information to other views. I would prefer approach2 here as you also intent to use. For header and command region you may create different module also. Lets hope we hear few more opinion here.

Regards
Santosh