In question Using MvvmCross from content providers and activities I wanted to know of how to initialize the MvvmCross system.
The answer given worked then, but with recent updates of MvvmCross the function which I used (MvxAndroidSetupSingleton.GetOrCreateSetup()) has been deprecated.
I have now changed my initialization and it seems to work so far, but is it correct and proper? Should I do things differently to improve portability?
Setup class, in platform specific DLL for Android:
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
// e.g. Cirrious.MvvmCross.Plugins.Visibility.PluginLoader.Instance.EnsureLoaded();
}
public static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
{
// Log exception info etc
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…