Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add Prism for MVVM #304
Ok, sync'ed with Bart. We'll rally with Brain and Karl as well but the POR is the following.
General hopes are that prism will just role straight in with no additional work since we support two different MVVM frameworks already
@crutkas Prism is not an MVVM framework. Prism is well-architected guidance for building applications. The guidance is backed up by a framework for implementing that guidance.
One of the biggest roadblocks we'll face is how UPW constructs objects. Currently, UPW creates pages when they are navigated to, then resorts to using a view model locator for view model construction. Service locator is an anti-pattern. Additionally, it can't stand up to complex enterprise application demands.
Microsoft just released a book: Enterprise Application Patterns using Xamarin.Forms. This book clearly describes using a dependency injection container for Xamarin Apps, the same way WPF and ASP.NET MVC apps have been doing for years. I started using DI in 2008.
Unfortunately, UWP does not currently support using DI for page construction.
Prism uses a dependency injection container for ALL object construction. This is a well known, universally accepted best practice for building decoupled applications that can easily be modified and maintained over time.
Unless we can get the Windows Team to modernize UWP page construction, we'll have to write a Prism Navigation and Frame (or region) components to replace the current UPW implementations.
I think it would be a great win for UWP in general, to modernize object construction, follow inversion of control principles, and allow developers to register a container with the application frame/navigation implementation for all object construction.
When Prism constructions a page, it also constructs the associated view model and all of the view model's dependencies. In complex apps, view model dependencies can be a complex graph of objects. This is one reason why using a DI container is the best practice.
Prism is so much more than an MVVM framework.
Looking forward to Skyping and discussing.
@kdawg1406 what are your item requests for the platform. I'm not seeing anything listed on https://wpdev.uservoice.com/forums/110705-universal-windows-platform that reference prism. What APIs are missing? Does .NET Standard 2.0 have said APIs in it?
@kdawg1406 have you actually tried using PRISM for an enterprise application in UWP? It supports DI just fine for VMs. We have a healthcare application with several modules and over 80 pages running just fine with Prism (incl deep linking).
There are a few issues with application lifecycle and .NET Native to be solved, but other than that Prism for UWP has been usable for LOB apps for over 2 years now. Doing a full rewrite "just because we can" is a waste of time in my opinion. I'm not even sure where the "full rewrite" is coming from.
You are right that the navigation is different compared to Xamarin.Forms since the system uses types to navigate instead of the page instance itself. But that is how UWP works and how Xamarin.Forms works. I have already discussed this with Brian this week and I'll look into what is possible to have a uniform interface between Prism.Windows (UWP) and Prism.Forms. But if that is too complex, it shouldn't keep us from going forward with what we have (and works) to integrate with WTS (which is for UWP). Maybe @timheuer can give us some pointers, but if this isn't in the OS yet, not much we can do to inject pages.
Expect that some of the integration can be done by extending some of the existing templates to also support Prism.