1

Hi i'm currently implement MVVM in a WPF app i'm developing. I implemented the ViewModel and the Views by using 2 separate projects. Only the View is referencing from the ViewModel. However, i've come to a point where i need the information in the Settings class(auto generated by Visual Studio using the Settings dialogue in the Project's Properties) to the ViewModel. How do i do that since ViewModel shouldn't reference the View's classes and also Settings class has a internal modifier.

need your suggestions on this one...i'm using mvvm-light which has the Locator pattern..

thanks

icube
  • 2,578
  • 1
  • 30
  • 63

1 Answers1

0

Create an interface like this:

public interface IUserSettingsService
{
   string FooSetting { get; }
   bool BarSetting { get; }
}

Create an implementation of this service that will return values from the Settings class in your views project and register it in the service locator.

Then, in your view models project you can get it via the service locator. Something like this:

var mySettings = ServiceLocator.Instance.GetService<IUserSettingsService>();
Pavlo Glazkov
  • 20,498
  • 3
  • 58
  • 71
  • thanks for the starting point, but how do you "Create an implementation of this service that will return values from the Settings class"? how can i do this in the ViewModel when "i am not allowed" to reference the Settings class? i'm not sure if i understand your answer correctly.. maybe a sample project would help.. – icube Jan 24 '11 at 10:56
  • You should create the implementation in the VIEWS project where you CAN access the Settings class. – Pavlo Glazkov Jan 24 '11 at 11:05
  • @icude extract the information you need from Settings class consider it as Model and inject this Model to ViewModel class where you create ViewModel(in Views project). – Arseny Mar 11 '11 at 09:54