質問コンテンツ プロバイダーおよびアクティビティから 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
}