MVVM deep dive

You can get a different instance each time by passing a different key to the GetInstance method. However the instances will be cached, so if you do not want to keep them in the cache, you will need to call Unregister with the corresponding key.

I was creating the VM upfront because the MainVM was sending messages to the SecondaryVM. Since the registration to the Messenger is done in the SecondaryVm's constructor, it needs to be created before it can start receiving messages. The Messenger is great because it is very decoupled, but it is one of these cases where you need to do extra work to compensate the decoupling: The SecondaryVM is the target of messages even though the MainVM does not get any reference to it.

 

Ref:

http://channel9.msdn.com/Events/MIX/MIX11/OPN03

http://stackoverflow.com/questions/9342294/simpleioc-can-it-provide-new-instance-each-time-required/9350917#9350917

posted @ 2013-12-16 16:11  MinieGoGo  阅读(194)  评论(0编辑  收藏  举报