views:

789

answers:

2

Hi, I am starting to write an application in Silverlight with RIA services and SilverlightFx. Now this application is a pretty big one has has lot of interaction between controls.

As an estimate it will have around 60-70 user controls. Now my questions are..

  1. Is it good to choose .Net Ria and SilverlightFx? (My view is..It is not going to production very soon. And as it is a big one using frameworks will help unit testing and save development time once the frameworks are understood properly.)

  2. After reading through the blogs I am not really clear how SilverlightFx handles interaction between user controls. For example I have a user control (say "S") that have the search functionality...auto complete and all...Now I have another UserControl (Say "R") that displays the search results. The display result panel can be used from search user control or another user control (Say F) that gives all items of a particular category. I can not marge Search and Select Category into a single userontrol. So how to do it? If I create different ViewModels how they will interect with each other?

  3. Is it better to create Domain service context in each ViewModel or to use a single one across the application?

A: 

Hey there, first off i dont know if SLFX provides any useful features besides graphical interaction, i suggest you take a look at prism for proper MVVM integration and proper use of Regions in your design, and then communication between regions (simply speaking, usercontrols but a little more dynamic in its loading)

  1. Unit testing from SL3 interface means that you must have a means to simulate user input, there are quite a few ways todo this. One of the easiest is the MVVM approach and thereby simulating input into the viewmodel. prism support for SL3 will co-incide with the release of WPF 4.0. prism currently does support SL3 just not the navigation framework, as it clashes alot with prism's region navigation, but they perform different tasks and they dont overlap functionality.

    1. If you have usercontrols "S", and "R" then, they both will share a common datasource, being the viewmodel, therefore properties within the viewmodel can communicate with each other, this mostly happens when the OnPropertyChanged event is fired. or a button is clicked, then using prism's commanding, you can hookup a button control click method to a method in the viewmodel.

    2. It really depends on alot of things, such as concurrency, since all calls from SL3 are async, meaning you can shoot of 3 queries at once over the same domain context, and how many connections you want created to your WCF service. i havent used RIA enough to understand the implications of the choices you have, so i cant give you an exact answer, but the general rule is to keep db connections to a minimum (Domain context recycling does not automatically convert into less connections since WCF is stateless unless otherwise designed)

Neil
Are you telling to keep same ViewModel class for both "S" and "R" then again how usercontrol "F" will ommunicate with it? Or is it better to change my viewmodel such that both "S" "R" and "F" shares the same view model.
Tanmoy
If you have 4 controls on a single view(page), then all four controls share the same viewmodel, each view will have its own viewmodel, each view consists of multiple controls. the prism way of doing things is having regions within a single view(page) and each region has its own viewmodel, and then there is a mechanism to allow regions to communicate. if S, R, F and tightly coupled on a single view, then they should share the same viewmodel, theres no point in decoupling the viewmodels when the view explicity depends on them being tightly coupled.
Neil
ViewModels are specific to a view, and Models are specific to a ViewModel, this also works backwards.if you want a different ViewModel on each control, then i suggest you go the region route it makes more sense for your problem, but thats the point are you ever going to swap the implementation of a single control?
Neil
+2  A: 

Note to preface answer - I am the author of Silverlight.FX, and architect for RIA Services ... so factor in bias in the reply :-) ...

I did two blog posts on the combination of the two you might find helpful: here and here. These cover basic view model scenarios using a DomainContext and basic unit testing of view models using the Silverlight Unit Test Framework.

Silverlight.FX offers more than just graphical interaction. From the site (http://projects.nikhilk.net/SilverlightFX):

  • Application Model - SilverlightFX features a richer Application object providing a service model, an IoC container, support for theming, view model (M-V-VM), navigation and MVC, amongst various other features.
  • User Interface Components - SilverlightFX provides a small set of enhanced controls, support for Forms and Windows, master page like containers, layout controls and data-bound controls.
  • Declarative Views - SilverlightFX provides a framework for writing behaviors, actions, triggers, and commands, and also provides a set of out-of-the-box implementations.
  • Effects and Transitions - SilverlightFX provides a procedural animation framework capable of implementing tweens and interpolations and easing behaviors. Additionally it provides simple but broadly applicable animations that can be applied as effects and transitions to standard controls in a fully declarative manner.

The way to handle the notifications across view models would be to use some sort of event aggregator pattern that allows view models to publish and subscribe to events in a decoupled manner.

This feature isn't yet in Silverlight.FX, but is slated to go in hopefully soon. I demonstrated this sort of communication recently in my TechEd South Africa talk - check out the slides and code for an implementation of this: http://www.nikhilk.net/TechEd09-South-Africa-Samples.aspx.

Hope that helps.

NikhilK
Thanks Nikhil. I will have a look.
Tanmoy