c# - Multiple viewmodels using 1 model? -



c# - Multiple viewmodels using 1 model? -

i have viewmodel1 , viewmodel2.

viewmodel1 needs show info list of sort contained in model. viewmodel2 needs input info list contained in model.

so both viewmodel1 , viewmodel2 need "know" model.

what proper way in mvvm?

should create model in app , give viewmodel1 , viewmodel2 reference or?

i find helps if think of viewmodel beingness model, translated view.

you have few choices:

create controller sets viewmodel. selection if viewmodel needs info more 1 place. can either give viewmodel reference info needs, or create plain old .net object (pono) , have controller set you.

just pass reference viewmodel suggest. useful if no interaction required between different classes

wire eventaggregator, can used publish notification when models change, , pass repository viewmodels each of them can go , / store model when need to.

i lastly pattern it's scalable if find need more presenters or controllers access these kinds of models. lets inject repository, means can more move nice restful service-oriented architecture later.

if haven't done much dependency injection before please consider doing through constructor. help avoid situations things trying utilize viewmodels before they're ready, , lets viewmodels own work. might want @ frameworks unity or castle windsor can help kind of wiring, that's big enterprise projects (and not of them).

c# wpf mvvm

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -