c# - MVVM Light create multiple instance of DataService -


right using mvvm light achieve mvvm pattern. in view create multiple tabs , bind them multiple instances of 1 viewmodel. achieve with:

servicelocator.current.getinstance<viewmodel>(key); 

when this, every instance of viewmodel connected same 1 instance of dataservice registered in viewmodellocator:

simpleioc.default.register<idataservice, dataservice>(); 

but want have every instance of viewmodel 1 instance of dataservice. why? because each instance of viewmodel has same function requires other data.

how create in mvvm lights viewmodellocator new instance of dataservice when new instance of viewmodel? possible or isn't approach in mvvm pattern , failed understand dataservice correctly?

you can use overloaded version of register method create multiple instances of data service.

simpleioc.default.register<idataservice>(()=>new dataservice(),"viewmodel1"); simpleioc.default.register<idataservice>(()=>new dataservice(),"viewmodel2"); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -