58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
|
|
using System.IO;
|
||
|
|
using System.Windows;
|
||
|
|
using Microsoft.Extensions.Configuration;
|
||
|
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
|
using Microsoft.Extensions.Hosting;
|
||
|
|
using PiiRedaction.TestHarness.Wpf.DependencyInjection;
|
||
|
|
using PiiRedaction.TestHarness.Wpf.Services;
|
||
|
|
using PiiRedaction.TestHarness.Wpf.ViewModels;
|
||
|
|
|
||
|
|
namespace PiiRedaction.TestHarness.Wpf;
|
||
|
|
|
||
|
|
public partial class App : Application
|
||
|
|
{
|
||
|
|
private IHost? _host;
|
||
|
|
|
||
|
|
protected override async void OnStartup(StartupEventArgs e)
|
||
|
|
{
|
||
|
|
base.OnStartup(e);
|
||
|
|
|
||
|
|
_host = Host.CreateDefaultBuilder()
|
||
|
|
.ConfigureAppConfiguration((_, configuration) =>
|
||
|
|
{
|
||
|
|
configuration.SetBasePath(AppContext.BaseDirectory);
|
||
|
|
configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||
|
|
configuration.AddEnvironmentVariables();
|
||
|
|
})
|
||
|
|
.ConfigureServices((context, services) =>
|
||
|
|
{
|
||
|
|
services.AddPiiRedactionServices(context.Configuration);
|
||
|
|
services.AddSingleton<ITestPromptCatalog, TestPromptCatalog>();
|
||
|
|
services.AddSingleton<IRedactionAppService, RedactionAppService>();
|
||
|
|
services.AddSingleton<IScriptAnalysisService, ScriptAnalysisService>();
|
||
|
|
services.AddSingleton<IModelStatusService, ModelStatusService>();
|
||
|
|
services.AddSingleton<MainViewModel>();
|
||
|
|
services.AddSingleton<MainWindow>();
|
||
|
|
})
|
||
|
|
.Build();
|
||
|
|
|
||
|
|
Directory.SetCurrentDirectory(AppContext.BaseDirectory);
|
||
|
|
|
||
|
|
await _host.StartAsync().ConfigureAwait(true);
|
||
|
|
|
||
|
|
var mainWindow = _host.Services.GetRequiredService<MainWindow>();
|
||
|
|
mainWindow.Show();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override async void OnExit(ExitEventArgs e)
|
||
|
|
{
|
||
|
|
if (_host is not null)
|
||
|
|
{
|
||
|
|
await _host.StopAsync().ConfigureAwait(true);
|
||
|
|
_host.Dispose();
|
||
|
|
}
|
||
|
|
|
||
|
|
base.OnExit(e);
|
||
|
|
}
|
||
|
|
}
|