PIbd-42_Kashin_M.I_CPO_Cour.../EmployeeManagmentView/App.xaml.cs

48 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using EmployeeManagmentDataBaseImplement;
using EmployeeManagmentBusinessLogic.BusinessLogic;
using EmployeeManagmentContracts.BusinessLogicContracts;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using System;
using System.Windows;
namespace EmployeeManagmentView
{
public partial class App : Application
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
protected override void OnStartup(StartupEventArgs e)
{
var serviceCollection = new ServiceCollection();
ConfigureServices(serviceCollection);
_serviceProvider = serviceCollection.BuildServiceProvider();
try
{
var mainWindow = _serviceProvider.GetRequiredService<MainWindow>();
mainWindow.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при открытии MainWindow", MessageBoxButton.OK, MessageBoxImage.Error);
}
base.OnStartup(e);
}
private static void ConfigureServices(ServiceCollection services)
{
// Регистрация контекста базы данных с использованием конфигурации
services.AddLogging(configure => configure.AddConsole());
// Регистрация бизнес-логики и других сервисов
services.AddTransient<IPhisicalPersonLogic, PhisicalPersonLogic>();
services.AddTransient<IEmployeeLogic, EmployeeLogic>();
// Регистрация окон
services.AddTransient<MainWindow>();
}
}
}