Announcing MvvmNano – An MVVM Framework Tailored For Xamarin.Forms
When digging around Xamarin.Forms over the past holidays I almost accidentally created a new MVVM Framework. Here is the story behind.
Yet Another MVVM Framework? The Story Behind.
When a client of my company came to me asking for some honest advice for choosing the right technology for a new software they were planning, I presented them with all of the advantages and disadvantages of the various options the market provides us these days.
At the end of the day they decided to give Xamarin.Forms a try, always in mind that there is a fallback available with Xamarin.iOS and Xamarin.Android.
To lower the risk it was also clear to me, that we had to go with MVVM as a core concept, so in the worst-case scenario we could easily remove the UI layer which Xamarin.Forms provides, reuse our view models and all the application's logic below, and "just" (;-)) swap the platform-specific UI implementation.
Although I liked much of what I found was possible with Xamarin.Forms, I didn't think what Xamarin offers in terms of MVVM support was sufficient for our purpose. If you just put some view models behind ContentPages, but still use the native navigation system etc., you're tied to Forms till the last days of your app.
So I took a look at some MVVM frameworks available, but found nothing convincing me. I have been working for a long time with MvvmCross, which truly is an amazing framework for Xamarin.iOS and Xamarin.Android. But I found it a bit too heavy for using it with Xamarin.Forms because I clearly didn't need all of the core features like data-binding (already provided by Forms) etc.
So I thought of what the ideal framework would mean to me and wrote down some reference points which resulted in the manifesto of MvvmNano.
- Each View (aka Page) must have its own View Model.
- Views know their View Models, but not vice versa: View Models never know their Views.
- Therefore navigation works from View Model to View Model only, without involving the View.
- When navigating, passing complex objects along must be possible.
- There should be no limits in how to present Views.
- View Models must be easily testable, so Dependency Injection is a basic prerequisite.
- Both Views and View Models must be easy to clean up.
It took me only an hour or two to figure out that the core mechanics wasn't that difficult to build, and after solving some more sophisticated parts and refining the interfaces, the whole thing is now stable and ready to go.
Hope it will help someone else, too. And I think it might even be worth a look if you're completely fallen in love with Xamarin.Forms and don't need a fallback strategy ;-).
What do you think? Drop me a line and let me know!