Implement the change between loader & main screen while using the DI
This commit is contained in:
parent
85431a7ec3
commit
91fabb658d
@ -1,17 +1,61 @@
|
|||||||
|
using DataModel;
|
||||||
|
using DataModel.Database.Common;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace UI_WinForms;
|
namespace UI_WinForms;
|
||||||
|
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
|
internal const string VERSION = "v0.1.0";
|
||||||
|
internal static IServiceProvider SERVICE_PROVIDER;
|
||||||
|
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
private static void Main()
|
private static void Main()
|
||||||
{
|
{
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
|
Application.EnableVisualStyles();
|
||||||
|
|
||||||
// Start the loader screen:
|
// Start the loader screen:
|
||||||
var loader = new Loader();
|
var loader = new Loader();
|
||||||
Application.Run(loader);
|
Application.Run(loader);
|
||||||
|
|
||||||
// Start the main app:
|
//
|
||||||
Application.Run(new Main());
|
// Create the DI system
|
||||||
|
//
|
||||||
|
var builder = new HostBuilder();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add services
|
||||||
|
//
|
||||||
|
builder.ConfigureServices((hostContext, serviceCollection) =>
|
||||||
|
{
|
||||||
|
// The main form:
|
||||||
|
serviceCollection.AddSingleton<Main>();
|
||||||
|
|
||||||
|
// The database:
|
||||||
|
serviceCollection.AddDatabase(loader.DataFile, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get the host out of the DI system:
|
||||||
|
var host = builder.Build();
|
||||||
|
|
||||||
|
// Create a service scope:
|
||||||
|
using (var scope = host.Services.CreateScope())
|
||||||
|
{
|
||||||
|
// Get a service provider:
|
||||||
|
SERVICE_PROVIDER = scope.ServiceProvider;
|
||||||
|
|
||||||
|
// Apply database migrations:
|
||||||
|
using (var database = SERVICE_PROVIDER.GetRequiredService<DataContext>())
|
||||||
|
Setup.PerformDataMigration(database).Wait();
|
||||||
|
|
||||||
|
// Create the main window:
|
||||||
|
var mainWindow = SERVICE_PROVIDER.GetService<Main>();
|
||||||
|
|
||||||
|
// Start the app:
|
||||||
|
Application.Run(mainWindow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user