4

質問コンテンツ プロバイダーおよびアクティビティから MvvmCross を使用して、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
    }
4

1 に答える 1

3

私が使用した関数 (MvxAndroidSetupSingleton.GetOrCreateSetup()) は廃止されました。

MvvmCross 初期化の変更は、ユーザーが「複数のスプラッシュスクリーン」の問題を回避できるようにするために必要でした - https://github.com/slodge/MvvmCross/issues/274を参照してください。

これらの変更の核心は次のとおりです。

したがって、この変更により次の行が削除されたことがわかります。

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

そしてそれらを次のものに置き換えました:

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

したがって、変更はこの同じコードを反映する必要があります。

于 2013-07-04T09:16:28.377 に答える