Understanding Xamarin App startup when using regions. #2644
Unanswered
bakerhillpins
asked this question in
Xamarin.Forms
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So I've been using Prism.Forms for a while now and feel like I understand it reasonably well but I have limited experience with Prism.WPF and regions. I now need to look into region support for my current and future projects and to begin I started by experimenting with the "out of the box" project for WPF Regions -> visual studio project template "Prism Full App (.NET Core)".
Moving beyond the WPF basics, I've found a few simplistic Prism.Forms.Regions examples via internet search which make sense but really only scratch the surface. As a learning exercise I've opted to convert the visual studio project template "Prism Full App (.NET Core)" to a Xamarin.Forms example. Ideally the strict conversion could be converted into a Template for Xamarin.Forms and when I've finished learning (adding more advanced examples) it could get merged into the samples project. (Both of these outputs are goals)
So, that brings me up to where I am now and the question I have about Prism.Forms.Regions:
What is the expected plumbing for Xamarin App startup to support Regions?
Existing application startup design/paradigm:
If I create a new Prism project using Visual Studio Templates or visit the Prism.Forms Sample projects the apparent Application Startup pattern/paradigm is to navigate to the MainPage by overloading the PrismApplicationBase.OnInitialized() method as such:
Now Consider the documentation that suggests the following:
Using the above startup paradigm the discovery method is successful.
Now consider the Injection approach:
and then follows up with
Using the above startup paradigm the injection method is NOT successful. Specifically for the case where injection is to occur at module load. Note that I'm using the Prism.WPF template code to perform the Module Load scenario as shown below:
This is because the Navigation command in the overload of PrismApplicationBase.OnInitialized() occurs AFTER all registered modules are loaded and initialized. Thus, there are never any existing regions at the time IModule.RegisterTypes() or IModule.OnInitialize() is called. When comparing the Prism.Forms startup to the successful Prism.WPF startup I noted that the MainWindow is loaded/created in the PrismApplicationBase. CreateShell() method which occurs BEFORE all registered modules are loaded and initialized.
One cannot use the Xamarin.Forms startup paradigm either because it loads the MainPage in the App Constructor which is also after the Module load. I.e.
After reviewing the implementation of Prism.Forms I realized that I could overload PrismApplicationBase.InitializeModules() and get the injection discovery to work:
TL;DR
Ok. So now that you've made it this far, Is overloading PrismApplicationBase.InitializeModules() the way that I should be booting my Xamarin Prism Region based application? Or should the project consider adding a PrismApplicationBase. CreateShell() method?
Beta Was this translation helpful? Give feedback.
All reactions