47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
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.AddScoped<EinfuegenModel>();
|
|
services.AddScoped<EinfuegenWindow>();
|
|
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";
|
|
}
|
|
}
|
|
}
|