MVVM Implementing started

This commit is contained in:
2023-03-25 12:34:24 +01:00
parent 47535950b2
commit b1ef5cffb5
36 changed files with 844 additions and 5 deletions

View File

@@ -1,4 +1,8 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SewerStammGen.HostBuilders;
using SewerStammGen.ViewModel;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
@@ -13,5 +17,52 @@ namespace SewerStammGen
/// </summary>
public partial class App : Application
{
private readonly IHost _host;
public App()
{
_host = CreateHostBuilder().Build();
}
static IHostBuilder CreateHostBuilder(string[]? args = null)
{
return Host.CreateDefaultBuilder(args)
.AddConfiguration()
.AddServices()
.AddViewModels()
.AddStores()
.AddDBContext();
}
protected override void OnStartup(StartupEventArgs e)
{
Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
_host.Start();
MainWindow? window = new MainWindow() { DataContext = _host.Services.GetRequiredService<MainWindowViewModel>() };
window.Show();
base.OnStartup(e);
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
Exception ex = (Exception)e.ExceptionObject;
string text = "An application error occured. Plrease contact the Administrator with the following information:\n\n";
MessageBox.Show(text + " " + ex.Message + "\n\n" + ex.StackTrace);
}
catch (Exception ex2)
{
MessageBox.Show("Fatal Non-UI error", ex2.Message, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
throw new NotImplementedException();
}
}
}