123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.DependencyInjection;
- using System.Windows;
- using System.Windows.Controls;
- using UniformMaterialManagementSystem.Data;
- using UniformMaterialManagementSystem.Models;
- using UniformMaterialManagementSystem.Services;
- using UniformMaterialManagementSystem.ViewModels;
- using UniformMaterialManagementSystem.Views;
- using UniformMaterialManagementSystem.Views.LoginAndRegister;
- namespace UniformMaterialManagementSystem
- {
- public partial class App
- {
- public IServiceProvider Services { get; }
- public new static App Current => (App)Application.Current;
- public static LoginUser? CurrentUser { get; private set; }
- public App()
- {
- Services = ConfigureServices();
- this.InitializeComponent();
- using var dbContext = new SqliteContext();
- dbContext.Database.Migrate();
- }
- protected override void OnStartup(StartupEventArgs e)
- {
- //文本框Binding双向绑定了数据Text=“{UpdateSourceTrigger=PropertyChanged}”,但数据是double类型,手动输入数据时,小数点输入不进去,设置此属性
- FrameworkCompatibilityPreferences.KeepTextBoxDisplaySynchronizedWithTextProperty = false;
- base.OnStartup(e);
- }
- private static IServiceProvider ConfigureServices()
- {
- var services = new ServiceCollection();
- // DbContext 注册
- services.AddDbContext<SqliteContext>();
- // View 注册
- services.AddSingleton<MainWindow>();
- services.AddTransient<LoginPage>();
- services.AddTransient<RegisterPage>();
- services.AddSingleton<LoginAndRegisterWindow>();
- services.AddKeyedTransient<UserControl, HomePage>("HomePage");
- services.AddKeyedTransient<UserControl, MenuPage>("MenuPage");
- services.AddKeyedTransient<UserControl, SupervisionUnitPage>("SupervisionUnitPage");
- services.AddKeyedTransient<UserControl, MaterialCompany>("MaterialCompany");
- services.AddKeyedTransient<UserControl, ProductCompanyPage>("ProductCompany");
- services.AddKeyedTransient<UserControl, RolePage>("RolePage");
- services.AddKeyedTransient<UserControl, MaterialControl>("MaterialControl");
- services.AddKeyedTransient<UserControl, PersonalInfoPage>("PersonalInfoPage");
- services.AddKeyedTransient<UserControl, InspectApplyPage>("InspectApplyPage");
- services.AddKeyedTransient<UserControl, UsersControl>("UsersControl");
- services.AddKeyedTransient<UserControl, InspectionRecordPage>("InspectionRecordPage");
- services.AddKeyedTransient<UserControl, ContractPage>("ContractPage");
- services.AddKeyedTransient<UserControl, DeliveryReceiptControl>("DeliveryReceiptControl");
- services.AddKeyedTransient<UserControl, InspectionReportPage>("InspectionReportPage");
- services.AddKeyedTransient<UserControl, SampleRegistrationPage>("SampleRegistrationPage");
- services.AddKeyedTransient<UserControl, SelectApplyContractDialog>("SelectApplyContractDialog");
- services.AddKeyedTransient<UserControl, InspectionOrganizationPage>("InspectionOrganizationPage");
- services.AddKeyedTransient<UserControl, InspectionOrganizationPage>("InspectionOrganizationPage");
- services.AddKeyedTransient<UserControl, FactoryLicensePage>("FactoryLicensePage");
- // ViewModel 注册
- services.AddSingleton<MainWindowViewModel>();
- services.AddSingleton<LoginAndRegisterViewModel>();
- services.AddTransient<LoginPageViewModel>();
- services.AddTransient<RegisterPageViewModel>();
- services.AddTransient<HomePageViewModel>();
- services.AddTransient<MenuPageViewModel>();
- services.AddTransient<SupervisionUnitPageViewModel>();
- services.AddTransient<MaterialCompanyViewModel>();
- services.AddTransient<ProductCompanyPageViewModel>();
- services.AddTransient<RolePageViewModel>();
- services.AddTransient<MaterialViewModel>();
- services.AddTransient<PersonalInfoPageViewModel>();
- services.AddTransient<InspectApplyPageViewModel>();
- services.AddTransient<UsersViewModel>();
- services.AddTransient<SelectContractWindowViewModel>();
- services.AddTransient<InspectionRecordPageViewModel>();
- services.AddTransient<ContractPageViewModel>();
- services.AddTransient<DeliveryReceiptViewModel>();
- services.AddTransient<InspectionReportPageViewModel>();
- services.AddTransient<SampleRegistrationPageViewModel>();
- services.AddTransient<InspectionOrganizationPageViewModel>();
- services.AddTransient<FactoryLicensePageViewModel>();
- services.AddTransient<SelectApplyContractDialogViewModel>();
- services.AddTransient<InspectionOrganizationPageViewModel>();
- // Service 注册
- services.AddScoped(typeof(IDataBaseService<>), typeof(DataBaseService<>));
- return services.BuildServiceProvider();
- }
- internal static void SetCurrentUser(LoginUser? user)
- {
- CurrentUser = user;
- }
- }
- }
|