c# - Where to keep an object instance that I want to share across multiple ViewModels -


i'm architecturing game in c# & xaml using mvvm. game consists of main menu new game option. new game button takes player select page can type names of 2 players , select if it's player vs player game or player vs computer game. arrive @ game screen , play game.

my question is, keeping persistent info in game object contains properties such player player1 , player player 2 , reactivecollection<tile> tiles, etc. should make game instance static , done or there better way this?

i use game service.

public interface igameservice {     player playerone { get; set; }     player playertwo { get; set; }     tiles reactivecollection { get; set; } } 

then service can resolved class using ioc / dependency injection when viewmodels/app created. way can create singleton of service class can used viewmodel, sitll decoupled , testable. class implements igameservice can information/data game wants makes flexible. can change way information delivered without having change viewmodels consume service.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -