You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.7 KiB
60 lines
1.7 KiB
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using MultiTerm.Core.ViewModel;
|
|
using System.Windows;
|
|
using MultiTerm.Core.Helpers;
|
|
using Common.Logging;
|
|
using Common.Logger;
|
|
|
|
namespace MultiTerm.Wpf;
|
|
|
|
public partial class App : Application
|
|
{
|
|
public static IHost? AppHost { get; private set; }
|
|
|
|
public App()
|
|
{
|
|
// create dependency injection host
|
|
AppHost = Host.CreateDefaultBuilder()
|
|
.ConfigureServices((hostContext, services) =>
|
|
{
|
|
services.AddSingleton<MainWindow>();
|
|
services.AddSingleton<ILogger>(new SerilogLogger("C:/log/multiterm-log-.txt", true));
|
|
|
|
// viewmodels
|
|
services.AddSingleton<ShellViewModel>();
|
|
|
|
// application specific
|
|
services.AddTerminalViewModelFactory();
|
|
})
|
|
.Build();
|
|
}
|
|
|
|
protected override async void OnStartup(StartupEventArgs e)
|
|
{
|
|
await AppHost!.StartAsync();
|
|
|
|
// create logger and initialize
|
|
var logger = AppHost.Services.GetRequiredService<ILogger>();
|
|
logger.Initialize(LogLevel.Trace);
|
|
logger.LogInfo("Application started.", nameof(App));
|
|
|
|
// instanciate startup form and show
|
|
var startupForm = AppHost.Services.GetRequiredService<MainWindow>();
|
|
startupForm.Show();
|
|
|
|
base.OnStartup(e);
|
|
}
|
|
|
|
protected override async void OnExit(ExitEventArgs e)
|
|
{
|
|
// log application exit and stop logger (if still available)
|
|
var logger = AppHost!.Services.GetRequiredService<ILogger>();
|
|
logger?.LogInfo("Application exited.", nameof(App));
|
|
logger?.StopLogging();
|
|
|
|
await AppHost!.StopAsync();
|
|
base.OnExit(e);
|
|
}
|
|
|
|
}
|
|
|