// This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. // Copyright (C) Leszek Pomianowski and WPF UI Contributors. // All Rights Reserved. using Wpf.Ui.Demo.Mvvm.Views; namespace Wpf.Ui.Demo.Mvvm.Services; /// /// Managed host of the application. /// public class ApplicationHostService(IServiceProvider serviceProvider) : IHostedService { private INavigationWindow? _navigationWindow; /// /// Triggered when the application host is ready to start the service. /// /// Indicates that the start process has been aborted. public async Task StartAsync(CancellationToken cancellationToken) { await HandleActivationAsync(); } /// /// Triggered when the application host is performing a graceful shutdown. /// /// Indicates that the shutdown process should no longer be graceful. public async Task StopAsync(CancellationToken cancellationToken) { await Task.CompletedTask; } /// /// Creates main window during activation. /// private async Task HandleActivationAsync() { await Task.CompletedTask; if (!Application.Current.Windows.OfType().Any()) { _navigationWindow = (serviceProvider.GetService(typeof(INavigationWindow)) as INavigationWindow)!; _navigationWindow!.ShowWindow(); _ = _navigationWindow.Navigate(typeof(Views.Pages.DashboardPage)); } await Task.CompletedTask; } }