mvvm - Prism 6 and constructor calling -
based video brian lagunas (youtube link) started using prism 6. little bit confused, constructor of mainwindowviewmodel getting called. copied project , can't find part. if set break point in constructor, never gets there.
was no showing in video or something?
if have @ code presentation, can see brian using prism's attached dependency property couple view , viewmodel through viewmodellocator.
prism:viewmodellocator.autowireviewmodel="true" in video around 33:00 gives full explanation how viewmodellocator works: first builds viewmodel name out of view's name through convention. either resolves name type through ioc container or reflection. ioc pretty straight forward: give type or name , give instance. reflection part (when run without container), prism uses activator type create new instance.
in final code available on github, brian using unity ioc container. custom mappings sub-views (viewa/viewb) made in bootstrapper. there no custom mapping mainviewmodel, following process happens:
- the app starts mainwindow startup window.
- the attached property viewmodellocator gets 'triggered', internal logic map mainwindow mainwindowviewmodel
- as we're using unity, viewmodellocator asks instance of viewmodel
- unity create new mainwindowviewmodel object , constructor hit
so won't see new xxxviewmodel() in code, created. means have greater flexibility on hardcoded object creation when comes down adding dependencies.
Comments
Post a Comment