SUBD_LAB/SUBD_LABA/View/Program.cs
2024-05-21 22:20:17 +04:00

64 lines
1.8 KiB
C#

using Microsoft.Extensions.DependencyInjection;
using Database;
using System;
using Commentbase;
using Microsoft.VisualBasic;
using static System.Windows.Forms.DataFormats;
namespace View
{
public static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
[STAThread]
public static void Main()
{
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<MainForm>());
}
private static bool isPostgreSQL = true;
private static void ConfigureServices(ServiceCollection services)
{
if (isPostgreSQL)
{
services.AddTransient<Abstracts, ImplementsPostgres>();
}
else
{
services.AddTransient<Abstracts, ImplementsMongoDB>();
}
services.AddTransient<MainForm>();
services.AddTransient<FormAlbum>();
services.AddTransient<FormAlbums>();
services.AddTransient<FormLocation>();
services.AddTransient<FormLocations>();
services.AddTransient<FormAuthor>();
services.AddTransient<FormAuthors>();
services.AddTransient<FormPhoto>();
services.AddTransient<FormPhotos>();
services.AddTransient<FormComment>();
services.AddTransient<FormComments>();
}
public static void ChangeDB()
{
isPostgreSQL = !isPostgreSQL;
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
}
public static void ChangeDB(bool newIsPostrgeSQL)
{
if (newIsPostrgeSQL == isPostgreSQL)
return;
isPostgreSQL = newIsPostrgeSQL;
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
}
}
}