MvvmCross 初始化 [英] MvvmCross initialization
问题描述
有问题使用来自内容提供商和活动的 MvvmCross 我想要了解如何初始化 MvvmCross 系统.
In question Using MvvmCross from content providers and activities I wanted to know of how to initialize the MvvmCross system.
当时给出的答案有效,但随着 MvvmCross 最近更新,我使用的函数 (MvxAndroidSetupSingleton.GetOrCreateSetup()) 已被弃用.
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?
安装类,在 Android 平台特定的 DLL 中:
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
}
}
以及我在可移植核心库中的 App 类:
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
}
推荐答案
我使用的函数 (MvxAndroidSetupSingleton.GetOrCreateSetup()) 已被弃用.
the function which I used (MvxAndroidSetupSingleton.GetOrCreateSetup()) has been deprecated.
需要对 MvvmCross 初始化进行更改,以帮助用户避免多闪屏"问题 - 请参阅 https://github.com/slodge/MvvmCross/issues/274.
The changes to MvvmCross initialization were required to help users avoid 'multiple splashscreen' issues - see https://github.com/slodge/MvvmCross/issues/274.
这些变化的核心是:
- https://github.com/slodge/MvvmCross/commit/3735c73c73c73c73c73c73c73c73c73c737a373737a3c7373a3a3/li>
- https://github.com/slodge/MvvmCross/commit/37f9dc76d3eca1fd2a7379597b73365c772e23a3
因此您可以看到此更改删除了行:
So you can see that this change removed the lines:
- var setup = MvxAndroidSetupSingleton.GetOrCreateSetup(activity.ApplicationContext);
- setup.EnsureInitialized(androidView.GetType());
并将它们替换为:
+ var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(activity.ApplicationContext);
+ setupSingleton.EnsureInitialized();
因此您的更改需要反映相同的代码.
So your changes will need to reflect this same code.
这篇关于MvvmCross 初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!