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.