Prism How to bind Module View to app wide property
I know this may seem silly but, what is the best way to bind to
Application Wide properties using MVVM and Prism?
Problem: ConnectionStatus Status {...} (Implements INotifyPropertyChanged
etc..)
How do I go about accessing this property in specific modules? I want to
be able to use the Status property across different modules?
What is the best way of getting this data across different modules?
Solutions
Currently I am leaning towards having the following view model in the
infrastructure project (shared across modules)
namespace Project.Infrastructure
{
public class AppViewModel
{
public ConnectionStatus Status {...}
}
}
And in IoC define AppViewModel as Singleton, and pass this in the
constructor of ModuleViewModel
namespace Project.ModuleA
{
AppViewModel _appViewModel;
public class ModuleViewModel
{
public ModuleViewModele(AppViewModel appViewModel)
{
....
}
}
}
Question
Is this the best way to do this or is there a better way of doing this?
E.g.
Using EventAggregator and ConnectionStatusChangeEvent to subscribe and
publish to changes in the connection? But in this case if someone
subscribes to the event after it got pubblished (such as online) they will
not get any starting value, so a IStatusService could be used at the
start?
Using RegionContext and binding that to the Status property in the Shell?
But this seems to defeat the purpose of Shell not knowing what the Modules
use etc..
Or is there something that I have completely missed?
I have read the whole Prism(v4) documentation and just not 100% sure of
which is the best way of implementing this.
No comments:
Post a Comment