This moment has been a long eight months in the making. I have ignored my wife and children for days at a time, coded late into the nights and over the weekends getting ready for this moment. A lot of work went into today. The day that Prism for Xamarin.Forms 6.2.0 is released. That’s right, it finally happened. No more previews and no more waiting. Prism for Xamarin.Forms 6.2 is available for download on NuGet now.
There is support for even more dependency injection containers:
- Unity – https://www.nuget.org/packages/Prism.Unity.Forms/
- Autofac – https://www.nuget.org/packages/Prism.Autofac.Forms/
- Ninject – https://www.nuget.org/packages/Prism.Ninject.Forms/
- DryIoc – https://www.nuget.org/packages/Prism.DryIoc.Forms/
Now, a lot has changed since Prism for Xamarin.Forms was first released. You can check out the release notes for a full list of everything that was changed on the project site’s Wiki page. Let’s take a look at the most important changes (some of them breaking) and improvements you should know about.
New Bootstrapping Process
The first thing you’re going to realize when you upgrade your old Prism for Xamarin.Forms 6.0 projects to 6.2 is that you are immediately broken. Your going to get an error about the Bootstrapper class no being found. You’ll pop open intellisense looking to resolve the namespace, but instead you’ll be given the option to create the class. Your file will look a little something like this:
Well, here’s the thing… the Bootstrapper is GONE! It has been removed, and the concept no longer exists in Prism for Xamarin.Forms. Instead, you’ll want to have your App class derive from the new PrismApplication abstract class. This class will be found in the container package that you chose to use. So if you are using Prism.Unity.Forms, then it will be found in the Prism.Unity namespace. Your new App.cs file should look like this:
Update to View/ViewModel Registration/Navigation
Another small, but breaking change is the RegisterTypeForNavigation<TView, TViewModel>() extension method. Before if you used this method, it would register the View for navigation using the full name of the TViewModel. It wouldn’t actually use the TVIewModel type as the ViewModel, but only as a strongly typed key. You would normally use this method of registration so that you could use the INavigationService.NavigateAsync<TVIewModel>() method. This allowed you to perform a strongly typed navigation operation and get rid of those nasty magic strings.
This has been changed!
The new behavior is closer to what you probably originally expected to happened. When you use RegisterTypeForNavigation<TView, TViewModel>, you are now assigning the TViewModel as the ViewModel type to use as the BindingContext of the View being registered. This is actually has better performance than relying on the default naming convention behavior of the ViewModelLocator. You are no longer relying on reflection to find the type, instead yu are directly assigning it.
Also, INavigationService.NavigateAsync<TViewModel> has been REMOVED. Instead, it uses the default naming convention when registering views. But why Brian> Why did you remove that? Well there are a number of reasons, but here are the main reasons:
- No support for navigating to Views in un-referenced modules
- No support for deep linking
- No support for resetting the navigation stack like you can with an absolute URI
These are all related to the new features and improvements made to Prism for Xamarin.Forms since its first release. Now I know you are probably mad about this change. I am sure a lot of you really liked navigating using a ViewModel type. The good news is that you can still have ViewModel first navigation if you like. Just import these extension methods into your application, and go to town. Just realize that you will have the limitations mentioned above.
ViewModelLocator.AutowireViewModel Behavior Change
Another behavior change was made based on a ton of great feedback. The thought being that we are already creating the page and finding the ViewModel using a convention, can’t we just add the ViewModelLocator.AutowireViewModel property automatically? Why, yes we can. So we did. Starting with Prism for Xamarin.Forms 6.2, you no longer have to add the VIewModelLocator.AutowireViewModel=’True’ to the top of every view. It’s done automatically for you. You can still add it if you like, just so you know it’s there, but you don’t have to. The Prism Template Pack’s project and item template will continue to add the attached property for you. It makes it easier to opt-out (set to false) if you don’t want it.
Deep Linking Support
One of the coolest features added to Prism for Xamarin.Forms 6.2 is the support for Deep Linking. This is so cool, that Xamarin took a page out of Prism’s book and added additional support for it that was announced at the Xamarin Evolve 2016 Keynote. Heck, even Miguel said he would recommend Prism.
So what exactly is deep linking? I’m glad you asked. Deep linking gives you the ability to navigate to a predefined navigation stack using a simple URI. So if I wanted to launch my app from a website and have it navigate to a particular page while maintaining a back history, I would do something like this:
What’s that… you want parameters to? No problem! Better yet, each page can have its own parameter list.
The next great feature added was the ability to separate your application into modules, or separate projects. This allows you a lot of flexibility on how you develop your app and provide features to your end-users. You can load modules automatically when the app loads, or you can manually load a modules based on some user action, such as a user logging in or an in-app purchase.
Prism Template Pack Improvements
The last thing I want to mention is the improvements that were made to the Prism Template Pack that is available for Visual Studio and Xamarin Studio. The Prism for Xamarin.Forms project template now has a project wizard that lets you chose what projects you want added to your solution instead of adding everything under the sun. This should make you life a lot easier, and creating projects much faster.
Well, that about wraps it up for the important stuff. Make sure to check out the release notes for a list of all the changes. I will be working on updating the documentation, which as you know is always the last thing that a developer does. I will also work on getting some new samples in the repo that covers all the cool features Prism for Xamarin.Forms provides. I am also starting work on a brand new Prism for Xamarin.Forms Pluralsight course. So keep an eye out on my course list which can be seen on my author page for this new course. I hope to have it done within 6 weeks, and it should be published soon after. There’s a ton of content, so hopefully I don’t slip on the timeline.
Please, get involved with the project on GitHub. Be sure to provide your feedback, submit issues, submit features, and submit PR’s. This is your project, so make it what you want it to be. As always, feel free contact me on my blog, connect with me on Twitter (@brianlagunas), or leave a comment below for any questions or comments you may have.