Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Prism/DryIOC object not updated after injecting in ViewModel constructor

$
0
0

I'm running into an issue where an object injected via Prism's container doesn't have the correct values after it's injected to the ViewModel constructor. I've created a sample to illustrate the problem. I can't post links, but it's on Github /RikDriever/DITest

Basically what I'm trying to do is:

  • Create an instance of an object in App.xaml.cs
  • Register the instance with the container
  • Update the object asynchronously while a splash page is displayed
  • Navigate to the MainPage when the updating is finished
  • Use the object in the MainPageViewModel constructor

The problem lies in the fact that when I'm assigning a new instance of the object to the instance that's registered with the container, the values aren't copied. So this doesn't work: _myData = await MyDataFactory.GetDataAsync(); because GetDataAsync returns a new MyData object. In the sample project I've commented out a line that does give the desired results, but it's not asynchronous: MyDataFactory.GetData(ref _myData);

Any ideas or should I perhaps rethink my design and use another way to get the data to the MainPageViewModel constructor? I should mention that several ViewModels in my real project use the same instance of the data object.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>