0

DB を必要とする MvvmCross アプリケーションを作成しています。私は N+1 KittenDB の例に従っています。DataStore の初期化子が呼び出される方法がわかりません。FirstViewModel のイニシャライザがパラメータとして持っていることに注意しました。

コードを実行すると、

Unhandled Exception:
Cirrious.CrossCore.Exceptions.MvxException: Failed to construct and initialise ViewModel for type VrWizard.Core.FirstViewModel

私のイニシャライザは

private IRepository _repository;
public FirstViewModel(IRepository repository)
{
    _repository  = repository;

}

リポジトリは、DataStore の私のバージョンです。

public Repository(ISQLiteConnectionFactory factory)
{
    _connection = factory.Create ("vrwizard.sql");
    CreateTables ();
}

リポジトリを初期化するにはどうすればよいですか?

ドン・フレンチ

9/23追記

これは、Android でのエラーのスタック トレースです。iPhoneでも同じエラーが発生します。

mvx:Diagnostic:  1.95 Creating ViewModel for ActionMain
[mvx]   2.07 Problem creating viewModel of type FirstViewModel - problem MvxException: Failed to resolve parameter for parameter factory of type ISQLiteConnectionFactory when creating VrWizard.Core.Services.DataStore.RepositoryService
[mvx]     at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.GetIoCParameterValues (System.Type type, System.Reflection.ConstructorInfo firstConstructor) [0x00000] in <filename unknown>:0 
[mvx]   at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x00000] in <filename unknown>:0 
[mvx]   at Cirrious.CrossCore.Mvx.IocConstruct (System.Type t) [0x00000] in <filename unknown>:0 
[mvx]   at Cirrious.CrossCore.IoC.MvxLazySingletonCreator.get_Instance () [0x00000] in <filename unknown>:0 
[mvx]   at Cirrious.CrossCore.IoC.MvxTypeExtensions+<>c__DisplayClass43.<RegisterAsLazySingleton>b__42 () [0x00000] in <filename unknown>:0 
[mvx]   at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer+ConstructingSingletonResolver.Resolve () [0x00000] in <filename unknown>:0 
[mvx]   at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, ResolveOptions resolveOptions, System.Object& resolved) [0x00000] in <filename unknown>:0 
[mvx]   at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, System.Object& resolved) [0x00000] in <filename unknown>:0 
[mvx]   at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.TryResolve (System.Type type, System.Object& resolved) [0x00000] in <filename unknown>:0 
[mvx]   at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.GetIoCParameterValues (System.Type type, System.Reflection.ConstructorInfo firstConstructor) [0x00000] in <filename unknown>:0 
[mvx]   at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x00000] in <filename unknown>:0 
[mvx]   at Cirrious.CrossCore.Mvx.IocConstruct (System.Type t) [0x00000] in <filename unknown>:0 
[mvx]   at Cirrious.MvvmCross.ViewModels.MvxDefaultViewModelLocator.TryLoad (System.Type viewModelType, IMvxBundle parameterValues, IMvxBundle savedState, IMvxViewModel& viewModel) [0x00000] in <filename unknown>:0 
mvx:Warning:  2.07 Problem creating viewModel of type FirstViewModel - problem MvxException: Failed to resolve parameter for parameter factory of type ISQLiteConnectionFactory when creating VrWizard.Core.Services.DataStore.RepositoryService
      at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.GetIoCParameterValues (System.Type type, System.Reflection.ConstructorInfo firstConstructor) [0x00000] in <filename unknown>:0 
  at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x00000] in <filename unknown>:0 
  at Cirrious.CrossCore.Mvx.IocConstruct (System.Type t) [0x00000] in <filename unknown>:0 
  at Cirrious.CrossCore.IoC.MvxLazySingletonCreator.get_Instance () [0x00000] in <filename unknown>:0 
  at Cirrious.CrossCore.IoC.MvxTypeExtensions+<>c__DisplayClass43.<RegisterAsLazySingleton>b__42 () [0x00000] in <filename unknown>:0 
  at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer+ConstructingSingletonResolver.Resolve () [0x00000] in <filename unknown>:0 
  at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, ResolveOptions resolveOptions, System.Object& resolved) [0x00000] in <filename unknown>:0 
  at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, System.Object& resolved) [0x00000] in <filename unknown>:0 
  at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.TryResolve (System.Type type, System.Object& resolved) [0x00000] in <filename unknown>:0 
  at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.GetIoCParameterValues (System.Type type, System.Reflection.ConstructorInfo firstConstructor) [0x00000] in <filename unknown>:0 
  at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x00000] in <filename unknown>:0 
  at Cirrious.CrossCore.Mvx.IocConstruct (System.Type t) [0x00000] in <filename unknown>:0 
  at Cirrious.MvvmCross.ViewModels.MvxDefaultViewModelLocator.TryLoad (System.Type viewModelType, IMvxBundle parameterValues, IMvxBundle savedState, IMvxViewModel& viewModel) [0x00000] in <filename unknown>:0 
[MonoDroid] UNHANDLED EXCEPTION: Cirrious.CrossCore.Exceptions.MvxException: Failed to construct and initialise ViewModel for type VrWizard.Core.FirstViewModel from locator MvxDefaultViewModelLocator - check MvxTrace for more information
[MonoDroid] at Cirrious.MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (Cirrious.MvvmCross.ViewModels.MvxViewModelRequest,Cirrious.MvvmCross.ViewModels.IMvxBundle,Cirrious.MvvmCross.ViewModels.IMvxViewModelLocator) <0x00148>
[MonoDroid] at Cirrious.MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (Cirrious.MvvmCross.ViewModels.MvxViewModelRequest,Cirrious.MvvmCross.ViewModels.IMvxBundle) <0x0006b>
[MonoDroid] at Cirrious.MvvmCross.Droid.Views.MvxAndroidViewsContainer.DirectLoad (Cirrious.MvvmCross.ViewModels.IMvxBundle,System.Type) <0x0008b>
[MonoDroid] at Cirrious.MvvmCross.Droid.Views.MvxAndroidViewsContainer.Load (Android.Content.Intent,Cirrious.MvvmCross.ViewModels.IMvxBundle,System.Type) <0x000ab>
[MonoDroid] at Cirrious.MvvmCross.Droid.Views.MvxActivityViewExtensions.LoadViewModel (Cirrious.MvvmCross.Droid.Views.IMvxAndroidView,Cirrious.MvvmCross.ViewModels.IMvxBundle) <0x00137>
[MonoDroid] at Cirrious.MvvmCross.Droid.Views.MvxActivityViewExtensions/<>c__DisplayClass3.<OnViewCreate>b__1 () <0x00027>
[MonoDroid] at Cirrious.MvvmCross.Views.MvxViewExtensionMethods.OnViewCreate (Cirrious.MvvmCross.Views.IMvxView,System.Func`1<Cirrious.MvvmCross.ViewModels.IMvxViewModel>) <0x00053>
[MonoDroid] at Cirrious.MvvmCross.Droid.Views.MvxActivityViewExtensions.OnViewCreate (Cirrious.MvvmCross.Droid.Views.IMvxAndroidView,Android.OS.Bundle) <0x001d7>
[MonoDroid] at Cirrious.MvvmCross.Droid.Views.MvxActivityAdapter.EventSourceOnCreateCalled (object,Cirrious.CrossCore.Core.MvxValueEventArgs`1<Android.OS.Bundle>) <0x000f7>
[MonoDroid] at (wrapper delegate-invoke) System.EventHandler`1<Cirrious.CrossCore.Core.MvxValueEventArgs`1<Android.OS.Bundle>>.invoke_void__this___object_TEventArgs (object,Cirrious.CrossCore.Core.MvxValueEventArgs`1<Android.OS.Bundle>) <0x000ab>
[MonoDroid] at Cirrious.CrossCore.Droid.Views.MvxDelegateExtensionMethods.Raise<Android.OS.Bundle> (System.EventHandler`1<Cirrious.CrossCore.Core.MvxValueEventArgs`1<Android.OS.Bundle>>,object,Android.OS.Bundle) <0x0004b>
[MonoDroid] at Cirrious.CrossCore.Droid.Views.MvxEventSourceActivity.OnCreate (Android.OS.Bundle) <0x00033>
[MonoDroid] at VrWizard.Droid.FirstView.OnCreate (Android.OS.Bundle) <0x0001b>
[MonoDroid] at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <0x0005b>
[MonoDroid] at (wrapper dynamic-method) object.23d26989-db28-4670-bfbb-658531972ead (intptr,intptr,intptr) <0x00043>
[mono] 
[mono] Unhandled Exception:
[mono] Cirrious.CrossCore.Exceptions.MvxException: Failed to construct and initialise ViewModel for type VrWizard.Core.FirstViewModel from locator MvxDefaultViewModelLocator - check MvxTrace for more information
[mono]   at Cirrious.MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request, IMvxBundle savedState, IMvxViewModelLocator viewModelLocator) [0x00000] in <filename unknown>:0 
[mono]   at Cirrious.MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request, IMvxBundle savedState) [0x00000] in <filename unknown>:0 
[mono]   at Cirrious.MvvmCross.Droid.Views.MvxAndroidViewsContainer.DirectLoad (IMvxBundle savedState, System.Type viewModelTypeHint) [0x00000] in <filename unknown>:0 
[mono]   at Cirrious.MvvmCross.Droid.Views.MvxAndroidViewsContainer.Load (Android.Content.Intent intent, IMvxBundle savedState, System.Type viewModelTypeHint) [0x00000] in <filename unknown>:0 
[mono]   at Cirrious.MvvmCross.Droid.Views.
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: Cirrious.CrossCore.Exceptions.MvxException: Failed to construct and initialise ViewModel for type VrWizard.Core.FirstViewModel from locator MvxDefaultViewModelLocator - check MvxTrace for more information
[mono-rt]   at Cirrious.MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request, IMvxBundle savedState, IMvxViewModelLocator viewModelLocator) [0x00000] in <filename unknown>:0 
[mono-rt]   at Cirrious.MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request, IMvxBundle savedState) [0x00000] in <filename unknown>:0 
[mono-rt]   at Cirrious.MvvmCross.Droid.Views.MvxAndroidViewsContainer.DirectLoad (IMvxBundle savedState, System.Type viewModelTypeHint) [0x00000] in <filename unknown>:0 
[mono-rt]   at Cirrious.MvvmCross.Droid.Views.MvxAndroidViewsContainer.Load (Android.Content.Intent intent, IMvxBundle savedState, System.Type viewModelTypeHint) [0x00000] in <filename unknown>:0 
[mono-rt]   at Cirrious.MvvmCross
4

4 に答える 4

3

見過ごされているかもしれないいくつかのヒント (Stuart の例にあります):

  • Sqlite プラグインを初期化する必要がある場所で、ブートストラップ クラスを探します。

    Cirious.CrossCore.Plugins の使用;

    namespace myapp.UI.Android.Bootstrap
    {
        public class SqlitePluginBootstrap
            : MvxPluginBootstrapAction<Cirrious.MvvmCross.Plugins.Sqlite.PluginLoader>
        {
        }
    }
    

次に、エラーをより徹底的にチェックします。ほとんどの場合、より多くの情報が提供されますが、どのパラメーターを構築できませんでしたか。

3 番目: サービスの複数のインスタンスを構築すると、Sqlite 設定の特定の状況下でエラーが発生する可能性があります。

これが始めるのに役立つことを願っています。

于 2013-09-23T14:32:42.057 に答える