/// <summary> /// This serves as the main function of the complete application. It creates initial state, consisting of the /// initial model and view model, and ties together the view and the dispatching function through an /// <see cref="ApplicationModel"/> object. All dependencies of the model, like our small data access layer, /// are also initialized here and passed to the model. I like the term "composition root" for describing this /// place in the system. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Application_Startup(object sender, StartupEventArgs e) { // Create the initial model and view model. var stampService = new WorldStampKnowledgeBaseService(); var initialModel = Stamps.Model.Model.smallCollection(stampService); var initialViewModel = Stamps.ViewModel.ViewModel.initialViewModel(initialModel); var application = new ApplicationModel(initialModel, initialViewModel); var mainWindow = new MainWindow(initialViewModel, application); mainWindow.Show(); }
/// <summary> /// Initializes the main view (window) and renders the initial view based on the initial view model. /// </summary> /// <param name="initialViewModel"> /// The initial view model. /// </param> /// <param name="applicationModel"> /// The object which provides updates of the view model and a way of sending messages. /// </param> public MainWindow(StampCollectionViewModel initialViewModel, ApplicationModel applicationModel) { InitializeComponent(); this.applicationModel = applicationModel; // Render the initial view. this.Render(initialViewModel); // (IR) // Subscribe to changes in the view model. Each time a new view model arrives, render it. this.applicationModel.ViewModel.Subscribe(this.Render); /* We could avoid initial explicit call for initial rendering (IR) by using some fancy Rx subject which * sends the initial model already upon subscription. I kept things simple here, because this is an * irrelevant implementation detail. */ }