Aufgabe WPF
This commit is contained in:
44
FahzeugWPF/App.xaml.cs
Normal file
44
FahzeugWPF/App.xaml.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using FahrzeugDatenBank;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
|
||||
namespace FahzeugWPF
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
public static ServiceProvider ServiceProvider { get; private set; }
|
||||
|
||||
public App()
|
||||
{
|
||||
IConfiguration configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: false, reloadOnChange: true).Build();
|
||||
|
||||
ServiceCollection services = new ServiceCollection();
|
||||
|
||||
services.AddScoped<IKonfigurationsleser>(sp => new Konfigurationsleser(configuration));
|
||||
services.AddScoped(sp => new FahrzeugRepository(sp.GetRequiredService<IKonfigurationsleser>().LiesDBVerebindung()));
|
||||
services.AddScoped<FahrzeugeModell>();
|
||||
services.AddSingleton<MainWindowViewModel>();
|
||||
services.AddSingleton<MainWindow>();
|
||||
|
||||
ServiceProvider = services.BuildServiceProvider();
|
||||
}
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
this.MainWindow = ServiceProvider.GetService<MainWindow>();
|
||||
this.MainWindow.DataContext = ServiceProvider.GetService<MainWindowViewModel>();
|
||||
this.MainWindow.Show();
|
||||
}
|
||||
|
||||
private string GetConnectionString()
|
||||
{
|
||||
return "Server=localhost;User ID=admin;Password=admin;Database=FahrzeugDB";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user