xamarin - MvvmCross 初始化

标签 xamarin xamarin.android mvvmcross

有问题 Using MvvmCross from content providers and activities我想知道如何初始化 MvvmCross 系统。

给出的答案当时有效,但随着 MvvmCross 最近的更新,我使用的函数 (MvxAndroidSetupSingleton.GetOrCreateSetup()) 已被弃用。

我现在已经改变了我的初始化,到目前为止它似乎可以工作,但它是否正确和正确?我应该以不同的方式做事来提高便携性吗?

安装类,在 Android 平台特定的 DLL 中:

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 类:
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
    }

最佳答案

the function which I used (MvxAndroidSetupSingleton.GetOrCreateSetup()) has been deprecated.



需要对 MvvmCross 初始化进行更改以帮助用户避免“多闪屏”问题 - 参见 https://github.com/slodge/MvvmCross/issues/274 .

这些变化的核心是:
  • https://github.com/slodge/MvvmCross/commit/37f9dc76d3eca1fd2a7379597b73365c772e23a3

  • 因此,您可以看到此更改删除了以下行:
    -  var setup = MvxAndroidSetupSingleton.GetOrCreateSetup(activity.ApplicationContext);
    -  setup.EnsureInitialized(androidView.GetType());
    

    并将它们替换为:
    +  var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(activity.ApplicationContext);
    +  setupSingleton.EnsureInitialized(); 
    

    因此,您的更改将需要反射(reflect)相同的代码。

    关于xamarin - MvvmCross 初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17466140/

    相关文章:

    ios - Xamarin.iOS 每天自动更改本地通知标题

    ios - 从 IntPtr 句柄获取 Xamarin.iOS NSObject(新的或缓存的)

    c# - Android 单声道中的 OnGlobalLayoutListener

    android - 从 MvvmCross 中删除 System.ServiceModel

    ios - 在“Cirrious.MvvmCross.Plugins.DownloadCache.MvxFileDownloadCache/Timer”中找不到嵌套类型

    c# - 遵循指南后,Xamarin iOS 应用程序被 UIWebView 拒绝

    c# - MvxGridView ItemClick 未触发

    android - 让 MvxAutoCompleteTextView 工作

    windows-phone-7 - MvvmCross vnext : CheckBox CheckedChange event to a command with monodroid

    mvvm - MvvmCross:如何在Android上从常规 View 导航到Mvvm View 模型?