Share data between ViewModels

Nov 20, 2010 at 9:57 AM


In my application im having an options view. This view lets the user fill in some options / configuration he wants to use.

Now, I want to use the options filled in throughout the application. So the options must be available in all the ViewModels.

Whats best practice here using Caliburn Micro?

Thanks in advance.

Nov 20, 2010 at 12:55 PM

I recommend factoring out an OptionsViewModel and registering it as a Singleton with the IoC container. Then, any other class in your application that needs access to those settings can simply request it through constructor injection.

Nov 22, 2010 at 7:04 AM



I have read your post on the MefBootstrapper.

The only question I have is, how do I access the MefBootstrapper.GetInstance() from the ViewModel?

Do I need to create some kind of static IoC class that wraps this functionality?

Nov 22, 2010 at 8:19 AM
Edited Nov 22, 2010 at 8:20 AM

The Bootstrapper configures some static methods that are part of Caliburn.Micro framework by default.

In particular IoC.GetInstance, IoC.GetAllInstances and IoC.BuildUp are by default mapped to the equivalent Bootstrapped methods.

To retrieve an instance registered in the container, you can just call the IoC.Get<T> static function, given that you did not change the default behaviour.


By the way, if I understand your scenario correctly, you need to share some settings among different view-models. In such a case, it would maybe be worth to define a POCO (maybe implementing INotifyPropertyChanged if you need change notifications) used to store the relevant settings, and pass it as a constructor parameter to the view-models.

If the options are shared at the application level, you could register such object in the IoC and let the dependency be injected automatically.