Currently, I have a xamarin app that has a database, web service and 2 other services to handle the logic between the database/web service and the ui. I'm trying to make it all async, and therefore I am having race condition issues occur. For the view models, I am using DI. While with the services I am treating them like I treat the navigation and putting them in SimpleIoc. Instantiating these services all occur in App.Xaml.cs. my issue is that the 2 other logic services are dependent on the web and database services. If one of those for some reason don't get initialized quick enough, then the 2 devices return null exception on those items. And because I create these services in App.xaml.cs, I can't do the .ContinueWith() on my asynchronous initializing methods.

My questions are then, what would be a better way to do notify my two services when the web and database services are ready to use, how do I queue up calls to these services when they are initializing, and is there a better approach to what I am doing?

  • I don't understand how you logic services get connected to your database and web service services (it sounds like that these are actually gateways). If your logic services use the SimpleIoc Container how can the gateways (database/web service) be not ready to use? – andih May 26 '17 at 7:51
  • @andih that is the issue as to what i am experiencing. Sometimes, the services work, sometimes they dont. If i slowly step through the beginning of the applicaiton, it works, but if I let it run on its own, it sometimes does not work and throws a null exception on the database as the application did not get the current database context. – Michael Gulik May 30 '17 at 16:29
  • I think that's more something that belongs to Stackoverflow. You should also post the code (example) how you load the dependent classes and whether you use the default (Singleton) or not when you get the classes from SimpleIoc. – andih May 31 '17 at 3:45

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.