I'am using mvvm light SimpleIoC in a Xamarin project and use an instance key to get some view model.
SimpleIoc.Default.GetInstance<ContextViewModel>("contextIdentifier");
Is there a way to get this instance key in the instance itself like other dependencies, in constructor ?
I know i can create and set a custom property on my ContextViewModel
but as my class need this value to work, i don't like the idea that i can get an "non-operationnal instance" of this view model.
Edit with more informations, to explain why i want my ViewModel instance know about its identifier :
It's a Xamarin.iOS application (ViewController
are created by storyboard).
In my app, i have multiple instance of the same view controller (and in the same UITabBarController
), and so, i need a different ViewModel instance for each view controller instance.
As my ViewModel need an id to get some data from database, I thought I would use this identifier also as instance identifier.
I can make it works by getting my ViewModel instance in the ViewDidLoad() method of my view controller, and call some Setters on it, but i don't like this (maybe i'm wrong :)) because in my mind, an IoC should only return operationnal instances (without needs of call multiple setters).
Best regards.