I am totally new in developing with Xamarin and I try to use the MvvmCross library in a shared project for all platforms. It seems that I succesfully added the libraries in each project, but now I am confused how to start. I tried to follow the documentation, but I think I didnt understand it right. I can use the CreatableTypes Method, but there are no EndingWith or the other Methods from the documentation. The examples that I found are mostly about PCL. I even dont know if this is a version problem or if I missed something important at all. Any hint or link would be helpfull.
1 Answers
First of all be careful what informations you read, always check the date or you will waste your time with some articles which are outdated. The most important ressources are prolly the official sample: https://github.com/MvvmCross/MvvmCross-Samples
Normally you use the PCL for all the background stuffand there should be some class like this https://github.com/MvvmCross/MvvmCross-Samples/blob/master/TipCalc/TipCalc.Core/App.cs . In this class you should be able to register all your services like this for IoC:
public override void Initialize()
{
CreatableTypes().EndingWith("Service").AsInterfaces().RegisterAsSingleton();
And then MVVMCross automatically takes care of initializing it, if you do a constructor injection in the ViewModel as a Example...
public MainViewModel(IPreferenceService preferenceService)
{
// Do Something here with the Service
}
...and you just need to call to show it with it connected view:
ShowViewModel<MainViewModel>();
So basically try to understand the samples first, i think TipCalc is still mostly up to date, atleast it is MVVMCross 4.0 https://github.com/MvvmCross/MvvmCross-Samples/tree/master/TipCalc

- 643
- 8
- 19
-
Thank you for your answer. I will try to follow the sample. The outdated samples are a big problem to find the right thing. So it would work to use the same way in the shared project? Using the App.cs for registration and implement the Interface Setup in each project? Or I have to choose a PCL and reference it in my shared project? – guenes Jun 01 '16 at 12:58
-
Iam not that experienced with shared projects, but atleast the wiki says to rather relay on PCL: https://github.com/MvvmCross/MvvmCross-Forms/wiki/Shared-Project-vs.-Portable-Class-Libraries – Noires Jun 01 '16 at 13:13
-
Though that is for the Forms Part. If the methods arent available in the shared project, then you have to stick to PCL. – Noires Jun 01 '16 at 13:36