views:

392

answers:

1

Hi, I'm working on a line-of-business silverlight application and I need a piece of advice concerning managing RIA services context lifetime.

Application - afer a few simplifications - is build of one big tab control. At the beginning there are 2 tabs: customer list and invoice list. These are plain datagrids with filtering/sorting and that sort of stuff. User can add/edit customer or invoice selecting a row and double-clicking. Then the new tab is created with details of customer or invoice. User can open many tabs with different customers/invoices. After editing, user can save and close tab or just abandon edit and close.

The question is how to deal with data contexts.

Should I create one for customerlist and one for invoicelist and when user opens a new tab, I simply bind customer/invoive dataobject to control? This has an advantage that I dont need to refresh grids after saving changes. EDIT: This has some drawbacks. User can refresh grid - and what will happen to open detail tabs? User can also filter grid so some records being edited can be removed from datactx?

The other way is to create datacontext per tabitem. This is more safe but I need to handle refreshing grid(s).

I have no idea which method is better or maybe there is another alternative?

A: 

Use one ObservableCollection list in each case and it will automatically update the datagrids when items are changed.

sipwiz
Yeah, I'm using ObservableCollection and INotifiyChange. Then my grid is automatically refreshed when user changes details on separate tab. My question was if it's safe to use one datacontext for whole application and subsequent edits.
tomo
The main thing in a DataContext is the DataSource which in this case is your ObservableCollection. It's safe to use it as a data source for multiple UI elements. If you also have multiple threads operating on the ObservableCollection then you will need to take the normal precautions, such as making sure only a single thread can update it at any one time.
sipwiz