-1

I have created a Portable class library while developing a windows store app. In that app I have used MvvmCross and PCl. Now I want to use same PCl in my Android app which I am developing on Xamarin studio but its not working as expected. It is giving me some exceptions related to MvxSimpleIoCContainer. I have added the referance of MVVMcross hot tuna starter package to my PCL and android app,Do I need to do anything else for using PCl and MVVMcross in Xamarin.Android app?

2 Answers2

0

Looks like your Android app hasn't started MvvmCross. Have you added Setup class to Android project and marked your MainActivity as inheriting after MvxAcitivity ? If yes then could you post exact exception that it throws?

Immons
  • 257
  • 1
  • 11
  • Thanks for your reply. Yes I have added the setup class in my android project and inherited MvxActivity in in all my views. I is working fine when I am doing some simple test application like pring hello world. But when I am trying to implement constructor injection in my viewmodels then it is giving error. below are the exceptions – Moni Bhattacharya Jul 14 '15 at 04:04
  • at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x0006b] in :0 at Cirrious.CrossCore.Mvx.IocConstruct (System.Type t) [0x00006] in :0 at Cirrious.CrossCore.IoC.MvxLazySingletonCreator.get_Instance () [0x00020] in :0 at Cirrious.CrossCore.IoC.MvxTypeExtensions+<>c__DisplayClass49.b__48 () [0x00000] in :0 at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer+ConstructingSingletonResolver.Resolve – Moni Bhattacharya Jul 14 '15 at 04:12
  • So you are registering that DI services as lazy? Have you tried to register them with ConstructSingleton either with RegisterType? – Immons Jul 14 '15 at 05:49
  • no I have not tried that. Actually I am using MVVMCross which itself provide IOC. – Moni Bhattacharya Jul 14 '15 at 07:06
  • Yes, but you need to register services that you want to inject. Have you done that? What depdency you need to inject into your viewModels ? – Immons Jul 14 '15 at 16:39
  • Yes I have registered services like this CreatableTypes() .EndingWith("Service") .AsInterfaces() .RegisterAsLazySingleton(); – Moni Bhattacharya Jul 15 '15 at 03:08
  • and injecting my services through constructor injection like this – Moni Bhattacharya Jul 15 '15 at 03:12
  • private readonly IDatabaseService _dataService; public TestViewModel(IDatabaseService dataService) { _dataService = dataService; } – Moni Bhattacharya Jul 15 '15 at 03:12
  • Actually I was getting that error because of sqlite implementaion. Contructor injection is working. Thanks for your support. – Moni Bhattacharya Jul 15 '15 at 06:43
0

For hitting services in android we need to have internet enabled in emulators. Because of this issue PCL was not working in my android app. To enable those settings there is good link on stackoverflow

How to setup Android emulator proxy settings?

Also sqlite path needs to be passed from native platform because Isolated storage is platform dependent. My error was because of these issues.

Posting this answer after doing lot of R & D. I thought it could help other developers who are new in Xamarin.android.

Community
  • 1
  • 1