using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ReCodeItGUI_WPF.Services;
using ReCodeItGUI_WPF.ViewModels.Pages;
using ReCodeItGUI_WPF.ViewModels.Windows;
using ReCodeItGUI_WPF.Views.Pages;
using ReCodeItGUI_WPF.Views.Windows;
using System.IO;
using System.Reflection;
using System.Windows.Threading;
using Wpf.Ui;
namespace ReCodeItGUI_WPF
{
///
/// Interaction logic for App.xaml
///
public partial class App
{
// The.NET Generic Host provides dependency injection, configuration, logging, and other services.
// https://docs.microsoft.com/dotnet/core/extensions/generic-host
// https://docs.microsoft.com/dotnet/core/extensions/dependency-injection
// https://docs.microsoft.com/dotnet/core/extensions/configuration
// https://docs.microsoft.com/dotnet/core/extensions/logging
private static readonly IHost _host = Host
.CreateDefaultBuilder()
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); })
.ConfigureServices((context, services) =>
{
services.AddHostedService();
// Page resolver service
services.AddSingleton();
// Theme manipulation
services.AddSingleton();
// TaskBar manipulation
services.AddSingleton();
// Service containing navigation, same as INavigationWindow... but without window
services.AddSingleton();
// Main window with navigation
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
}).Build();
///
/// Gets registered service.
///
/// Type of the service to get.
/// Instance of the service or .
public static T GetService()
where T : class
{
return _host.Services.GetService(typeof(T)) as T;
}
///
/// Occurs when the application is loading.
///
private void OnStartup(object sender, StartupEventArgs e)
{
_host.Start();
}
///
/// Occurs when the application is closing.
///
private async void OnExit(object sender, ExitEventArgs e)
{
await _host.StopAsync();
_host.Dispose();
}
///
/// Occurs when an exception is thrown by an application but not handled.
///
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
// For more info see https://docs.microsoft.com/en-us/dotnet/api/system.windows.application.dispatcherunhandledexception?view=windowsdesktop-6.0
}
}
}