Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prism vs mvvm light for UWP application

We have a working project in Windows 8.1 which is made compatible to Win 10. Now the requirement is to convert this project to UWP. In the earlier project, we have used PRISM as the framework for MVVM. Now the problem is that for UWP application, the new version for Prism is not yet released and we are considering to use MVVMLight.

I am new to both these frameworks, ie, PRISM and MVVMLight. Now my question is how difficult will it be to move the codebase from PRISM to MVVMLight. If it will be difficult, should be wait for PRISM newer version to be released. And if we should move to MVVMLight, what major changes need to be done.

According to my observation, the codebase is highly coupled with PRISM where there is extensive use of interfaces like IResourceLoader, ISessionStateService and so on throughout the code. Also, I read that PRISM has a learning curve while MVVMLight does not. So if we do decide to move to MVVMLight, will I have to learn PRISM first to understand the codebase and then learn MVVMLight to port the codebase. If we decide to wait for newer version of PRISM to be released which is sometime this week, will there be major code changes?

How is Unit Testing supported with respect to both framework.

Since, there is not much time allotted for this task, which will be most efficient way to go ahead with?

like image 386
Aakansha Avatar asked Sep 23 '15 07:09

Aakansha


People also ask

What framework for MVVM should I use?

WPF Application Framework (WAF)

What is MVVM Light?

MVVM-light is a toolkit written in C# which helps to accelerate the creation and development of MVVM applications in WPF, Silverlight, Windows Store, Windows Phone and Xamarin.

What is Prism MVVM?

Prism provides an implementation of a collection of design patterns that are helpful in writing well-structured and maintainable XAML applications, including MVVM, dependency injection, commands, EventAggregator, and others. Prism's core functionality is a shared code base in a Cross Compiled .

Do I need a framework for MVVM?

MVVM pattern is not framework and doesn't require any framework to be used.


2 Answers

TL;DR: Compile the latest Prism code in anticipation of the new NuGet packages.

First of all a small intro on Prism to get everybody on the same foot. Prism is a MVVM guidance/framework created by Microsoft Patterns & Practices. They released up to version 5 for WPF/Silverlight. Next to that they also released Prism for Windows Runtime for Windows 8 and later updated to Win8.1/WP8.1 RT. These are 2 different codebases with the second one being more lightweight in the aspect of regions etc, but giving very useful support for application lifecycle management. It's a common misconception to think they're the same.

In March, ownership of Prism was transferred to the community as an open source project and is available on GitHub. They decided to move forward, merge the common code in a PCL core assemby and add support for Xamarin Forms.

As of today there is no RTM release of Prism 6 for UWP yet. The codebase is pretty close to be released with only a few minor issues open, but nothing major preventing most users to use the bits already. At this point of time I would tell you to clone the GitHub repository, compile the assemblies and start porting your app. There are a few breaking changes (mainly namespaces), but you should be up and running in no time. Once the RTM packages are available, drop the hard references and use NuGet.

I have already ported one of our smaller apps and I'm planning to port one of the larger LOB ones (over 60 screens) this weekend.


To come back to the discussion which MVVM framework to use. If you have an app of just a few pages, don't bother using a framework and keep your MVVM simple. If you're going for complex LOB apps, these frameworks have their advantages (and of course disadvantages). There are plenty of choices (MVVM Light, Prism, Caliburn Micro, ...) and all of them are good.

The fact that your colleagues choose for Prism might have a reason like Depechie mentioned. In first place I'm thinking about application lifecycle management where Prism has far superior support for.

With a correct use of base classes you should be able to refactor away most of the dependencies from every single ViewModel in case you want to switch to another framework after all.

The major differences (on top of my head) between Prism for Windows Runtime and MVVM Light that you will have to tackle when switching are VisualStateAwarePages, ViewModelLocator (auto vs property for each view), BindableBase for INotifyPropertyChanged and everything about application lifecycle management. Both frameworks are good, but I wouldn't recommend switching a full blown LOB application between them as it's just too much work (introducing possible bugs).

like image 50
Bart Avatar answered Oct 08 '22 19:10

Bart


Windows 10 UWP apps are far less suitable to any of the frameworks you mention. Their rich navigational capabilities and adaptive layouts means that it's hard to see how Prism would work well for you. As regards to MVVMLight, it offers very little above you rolling your own viewmodels, and by avoiding it you can dodge the possibility of a nasty lock-in that will bite you later (which it often does)

like image 39
Dean Chalk Avatar answered Oct 08 '22 18:10

Dean Chalk