lbugnion / mvvmlight

The main purpose of the toolkit is to accelerate the creation and development of MVVM applications in Xamarin.Android, Xamarin.iOS, Xamarin.Forms, Windows 10 UWP, Windows Presentation Foundation (WPF), Silverlight, Windows Phone.
http://www.mvvmlight.net
MIT License
1.17k stars 310 forks source link

Two different versions of ViewModelLocator? #57

Open abgenullt opened 5 years ago

abgenullt commented 5 years ago

Hi,

I've noticed, that you provide two different versions of the ViewModelLocator class. In the project template of the Visual Studio extension, there is one with a static constructor. But if you add the mvvmlight nuget package to your project, a class with a public constructor will be created.

The problem with the nuget version is, that the designer may call the public constructor more than once, if you rebuild the project and that results in some "class already registered..." errors. So, you need to add a .reset() call at the beginning of the constructor to fix that. So, I personally prefer the static version.

Is there a reason for that inconsistency and which one is the "correct" one?

Regards, abgenullt

yannduran commented 5 years ago

@lbugnion I'd also love to know the answer to this question.