Keep open screens updated - WPF/Prism/MEF/MVVM/EF

Topics: Prism v2 - WPF 4, Prism v4 - WPF 4
Mar 31, 2014 at 9:37 AM

In our WPF app implemented using Prism and MEF, UI layer is MVVM based and EF has been used in DAL.

When the data changes on one screen, we want to ensure that all open screens display the updated data. E.g. if we add a new customer in Add Customer screen, then the already open Search Customer should be refreshed with the newly added customer.

Currently we are using the EventAggregator and Publisher-Subscriber pattern for refreshing the data. The ViewModels (in UI layer) and the DbContext (in DAL) are disconnected. The ViewModels get the updated data by calling the methods in DAL.

Is there another way of ensuring that data is up-to-date across the application? I heard we can have one DbContext for the whole application to ensure this. Is that the right way to go when the data can be huge?

Please advise.
Mar 31, 2014 at 5:16 PM

The approach you mentioned of using EventAggregator would be correct. However, I don't completely understand what do you refer by having the ViewModels and DbContext disconnected when the ViewModels get the data by calling the DbContext's methods.

Anyway, regarding data consistency, the use of one only DbContext with a big load of data would depend on the complexity for managing the DB and maintaining its consistency. You should try to keep coherence in DB's data and try to avoid extra filters on information requests.

Gabriel Ostrowsky