Last active
October 21, 2017 09:52
-
-
Save andy51002000/ceb21e6dde2f33007e47c883c89cdd13 to your computer and use it in GitHub Desktop.
A class that provides the instance of ViewModel and inject db context into ViewModel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SimpleMVVM.Data; | |
using System.Collections.Generic; | |
namespace SimpleMVVM.ViewModels | |
{ | |
public class ViewModelLocator | |
{ | |
private Dictionary<string, ViewModelBase> modSet; | |
private FakeDatabase dbContext; | |
public ViewModelLocator() | |
{ | |
modSet = new Dictionary<string, ViewModelBase>(); | |
dbContext = new FakeDatabase(); | |
InitializeDatabase(); | |
MovieListViewModel movieListViewModel = new MovieListViewModel(dbContext); | |
modSet.Add("MovieListViewModel", movieListViewModel); | |
} | |
public MovieListViewModel MovieListViewModel | |
{ | |
get => (MovieListViewModel)modSet["MovieListViewModel"]; | |
} | |
public async void InitializeDatabase() | |
{ | |
await dbContext.LoadMoviesFromFile(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment