1

I am building a server manager application that displays list of servers. Each server provides some information which is arranged and grouped into 4 different windows.User can open any window from server's context menu. windows are opened and managed by ViewManager class which listens to different messages(via. messenger). I am using server ip as key for each instance in ServiceLocator. This way i can easily manage ViewModel instances of same type.

Problem I am facing is, how can i pass key to GetInstance() at runtime so that when window is initialized it uses the viewmodel with the specified key?

Currently i am using a static string variable(key) which i declared in ViewModelLocator.I initialize it with server's ip before instantiating window.

Is there any other solution?

Betson Roy
  • 131
  • 6
  • Can you provide some code of your ViewModelLocator and so on? – Franz Wimmer Feb 14 '16 at 12:22
  • @FranzWimmer Its the default ViewModelLocator . – Betson Roy Feb 14 '16 at 12:33
  • Possible duplicate of [http://stackoverflow.com/questions/30721678/servicelocator-get-instance-by-passing-construction-parameter](http://stackoverflow.com/questions/30721678/servicelocator-get-instance-by-passing-construction-parameter) – Lionel Pire Feb 14 '16 at 13:31
  • @LionelPire how is this duplicate? – Betson Roy Feb 16 '16 at 13:40
  • It means that the post I linked might answer your question since it's really similar – Lionel Pire Feb 16 '16 at 15:16
  • @LionelPire well it isn't.the link you posted talks about passing parameter to constructor of registered type and not to GetInstance().anyways thanks for the time you spend. – Betson Roy Feb 16 '16 at 17:23
  • Maybe this will answer you : http://stackoverflow.com/questions/13795596/how-to-use-mvvmlight-simpleioc if this doesn't please rephrase your questions as I don't really understand – Lionel Pire Feb 17 '16 at 13:55
  • @LionelPire I will rephrase the question as soon as i reach home.If you have a look at accepted answer in the link you gave,the second point has a code "SimpleIoc.Default.GetInstance(Guid.NewGuid().ToString());".here, new key is generated everytime i call GetInstance().I have a unique key and i want to use that instead of New Guid.my question is how can i pass that key to locator? – Betson Roy Feb 17 '16 at 14:07
  • Well there is your answer : call explicitely SimpleIoc.Default.GetInstance(myIP); whenever you need to do it at runtime – Lionel Pire Feb 17 '16 at 14:23
  • @LionelPire view creates the viewmodel.how can i tell the view that it is supposed to use the viewmodel with key "myip"? – Betson Roy Feb 17 '16 at 14:31

0 Answers0