DB integration added, multiple images for equipment
This commit is contained in:
+21
-3
@@ -3,13 +3,18 @@ using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Data.Core.Plugins;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using GazpromApp.Utils;
|
||||
using GazpromApp.ViewModels;
|
||||
using GazpromApp.Views;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GazpromApp;
|
||||
|
||||
public class App : Application
|
||||
{
|
||||
private static ServiceProvider? Services { get; set; }
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
@@ -17,14 +22,27 @@ public class App : Application
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
services.AddDbContext<AppDbContext>(options =>
|
||||
{
|
||||
var dbPath = new AppDbContext().DbPath;
|
||||
options.UseSqlite($"Data Source={dbPath}");
|
||||
});
|
||||
|
||||
services.AddTransient<MainWindowViewModel>();
|
||||
|
||||
Services = services.BuildServiceProvider();
|
||||
|
||||
var dbContext = Services.GetRequiredService<AppDbContext>();
|
||||
dbContext.Database.EnsureCreated();
|
||||
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
// Avoid duplicate validations from both Avalonia and the CommunityToolkit.
|
||||
// More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
|
||||
DisableAvaloniaDataAnnotationValidation();
|
||||
desktop.MainWindow = new MainWindow
|
||||
{
|
||||
DataContext = new MainWindowViewModel()
|
||||
DataContext = Services.GetRequiredService<MainWindowViewModel>()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user