Initializing MvvmCross

In question Using MvvmCross from content and action providers I wanted to know how to initialize the MvvmCross system.

Then the answer turned out to be processed, but with recent updates to MvvmCross, the function I used (MvxAndroidSetupSingleton.GetOrCreateSetup ()) is deprecated.

Now I changed my initialization and it seems to be working so far, but is it right and right? Should I do something different to improve portability?

DLL installation class for the Android platform:

public class Setup : MvxAndroidSetup { public Setup(Context applicationContext) : base(applicationContext) { } protected override IMvxApplication CreateApp() { // Create logger class which can be used from now on var logger = new AndroidLogger(); Mvx.RegisterSingleton(typeof(ILogger), logger); var app = new App(); InitialisePlatformSpecificStuff(); return app; } private void InitialisePlatformSpecificStuff() { // For instance register platform specific classes with IoC } } 

And my App class in the portable core library:

 public class App : MvxApplication { public App() { } public override void Initialize() { base.Initialize(); AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; InitialisePlugins(); InitaliseServices(); InitialiseStartNavigation(); } private void InitaliseServices() { CreatableTypes().EndingWith("Service").AsInterfaces().RegisterAsLazySingleton(); } private void InitialiseStartNavigation() { } private void InitialisePlugins() { // initialise any plugins where are required at app startup // eg Cirrious.MvvmCross.Plugins.Visibility.PluginLoader.Instance.EnsureLoaded(); } public static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e) { // Log exception info etc } 
+4
source share
1 answer

the function I used (MvxAndroidSetupSingleton.GetOrCreateSetup ()) is deprecated.

Changes to the initialization of MvvmCross were needed to help users avoid problems with multiple firewalls - see https://github.com/slodge/MvvmCross/issues/274 .

The core of these changes was:

So you can see that this change deleted the lines:

 - var setup = MvxAndroidSetupSingleton.GetOrCreateSetup(activity.ApplicationContext); - setup.EnsureInitialized(androidView.GetType()); 

and replaced them with:

 + var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(activity.ApplicationContext); + setupSingleton.EnsureInitialized(); 

Thus, your changes will have to reflect the same code.

+3
source

All Articles