Files
PIbd-32_BuslaevRoman_KOP/WinFormsComponentOrientedHost/Program.cs
2025-09-23 14:07:38 +04:00

56 lines
1.8 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using WinFormsComponentOrientedHost.Composition;
using WinFormsComponentOrientedHost.Infrastructure;
using WinFormsComponentOrientedHost.Licensing;
using WinFormsComponentOrientedHost.UI;
namespace WinFormsComponentOrientedHost;
internal static class Program
{
public static IConfiguration Configuration { get; private set; } = default!;
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
// Íàñòðàèâàåì êîíôèã
var builder = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false);
Configuration = builder.Build();
// Ïðîñòîé ëîããåð â Debug/MsgBox
var logger = new SimpleLogger();
// Ëèöåíçèÿ
var license = LicenseProvider.FromConfig(Configuration, logger);
// Çàãðóç÷èê ïëàãèíîâ
var pluginsPath = Configuration["Plugins:Path"] ?? ".\\Plugins";
var loader = new ReflectionLoader(pluginsPath, logger);
// HostServices
var host = new HostServicesImpl(license, logger);
var cs = Configuration["Database:ConnectionString"] ?? throw new Exception("No DB connection string");
var dbFactory = new WinFormsComponentOrientedHost.Data.AppDbContextFactory(cs);
host.Register<WinFormsComponentOrientedHost.Data.IAppDbContextFactory>(dbFactory);
try
{
using var db = dbFactory.CreateDbContext();
db.Database.EnsureCreated();
db.Database.Migrate();
}
catch (Exception ex)
{
logger.Error("DB migrate failed", ex);
}
Application.Run(new FormMain(Configuration, host, loader));
}
}