Controller + mvvm

Jul 17, 2009 at 6:00 AM

Hi List,

i have tho following structure in my code.

If i start a module i run a 'xxxController'. This Controller cleans up my MainRegion and start the 'xxxListPresenter' when DoubleClick a ListItem, the Controller will be informed to change from 'xxxListPresenter' to 'xxxDetailPresenter'.

In my DetailView i have 'Cancel' and #Save' Button. So far so good.

What is the best way to let my DetailPresenter and/or my Controller know what's going on?

Should the 'DetailPresenter', the 'DetailViewModel' or the Contoller' handle save of my Entity's.

Should i use Events or Commands to inform my Controller.

Thanks

Peter

 

Jul 17, 2009 at 6:10 PM

Hi Peter,

In this scenario whether to use events or commands is really a decision that should be made on the specific functionality you require. In my personal opinion, handle the save of your identities in any of those classes (you probably have a service to save the data, and Unity dependency injection, if you are using Unity, allows easy access to it) would be ok, but of course that really depends on what kind of logic you are using in each. Say, if you are handling the save functionality in the Controller, then your entire module (assuming the Controller works at module level), could use that functionality for maximum reusability.

If the scenario has no major complications, using a command in the ViewModel (where you already have the data with no need to pass it around), could a good approach. Take into account that if you do decide to use events, you can use standard .Net events since you are working with references to the Presenters/Controllers as they are in the same module.

You might find the Quickstarts and the Reference Implementation provided by the Guidance a good starting point. The Commanding Quickstast has a similar scenario for saving orders. The Reference Implementation also uses commands to save positions. The  EventAggregator Quickstart uses events to add funds to customers.

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman

Jul 18, 2009 at 8:57 AM

Hi Demian,

<

Say, if you are handling the save functionality in the Controller, then your entire module (assuming the Controller works at module level), could use that functionality for maximum reusability.

>

this seems to be a very flexibel way to handle many of the overall nedded tasks in a module.

thanks a lot

Peter

 

 

Sep 18, 2009 at 1:56 PM

Some of the Quickstarts use a Controller and some do not, and the RI does use Controllers.  Unfortunately the Prism docs make no mention of controllers.  What is the rhyme and reason behind Controllers?  I'm not following their pattern of use.  Help me please!  Thanks.

 

Sep 18, 2009 at 9:25 PM

Hi

There is no particular reason for using controllers. As you might notice, most of these are module level controllers, and instead of handling the activity of a particular view they coordinate the functionality of entire modules.

The following threads deal with this question:

Ward Bell explains more about managing views in these couple of posts (these are not related to controllers per se, but have some really interesting ideas in my opinion):

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman

Sep 21, 2009 at 5:53 AM

Hi dschenkelman

this was exactly what i'm looking for

Thanks

Peter