54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using System;
|
|
using System.Windows;
|
|
using BackgroundBuilder.Repositories;
|
|
using BackgroundBuilder.Services;
|
|
using BackgroundBuilder.ViewModels;
|
|
using BackgroundBuilder.Views;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
namespace BackgroundBuilder
|
|
{
|
|
public partial class App : Application
|
|
{
|
|
private readonly IHost _host;
|
|
|
|
public App()
|
|
{
|
|
_host = Host.CreateDefaultBuilder()
|
|
.ConfigureAppConfiguration(cfg =>
|
|
cfg.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true))
|
|
.ConfigureServices((_, services) =>
|
|
{
|
|
// Database & repository
|
|
services.AddSingleton<DatabaseService>();
|
|
services.AddScoped<IContatoRepository, PostgresContatoRepository>();
|
|
|
|
// New image service
|
|
services.AddSingleton<IImageService, ImageService>();
|
|
|
|
// New taskbar service
|
|
services.AddSingleton<ITaskbarService, TaskbarService>();
|
|
|
|
// VM & View
|
|
services.AddTransient<MainWindowViewModel>();
|
|
services.AddTransient<MainWindow>();
|
|
})
|
|
.Build();
|
|
}
|
|
|
|
private async void OnStartup(object sender, StartupEventArgs e)
|
|
{
|
|
await _host.StartAsync();
|
|
var window = _host.Services.GetRequiredService<MainWindow>();
|
|
window.Show();
|
|
}
|
|
|
|
protected override async void OnExit(ExitEventArgs e)
|
|
{
|
|
using (_host) { await _host.StopAsync(); }
|
|
base.OnExit(e);
|
|
}
|
|
}
|
|
} |