问题描述
有问题的使用来自内容提供商和活动的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
}
推荐答案
需要对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/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初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!