Added dependency injection

This commit is contained in:
MaddoScientisto 2024-10-14 22:18:03 +02:00
commit 39a9baf5c6
13 changed files with 59 additions and 581 deletions

34
imagecatalog/Program.cs Normal file
View file

@ -0,0 +1,34 @@
using ImageCatalog;
using ImageCatalog_2.Services;
using Microsoft.Extensions.DependencyInjection;
namespace ImageCatalog_2
{
static class Program
{
public static IServiceProvider ServiceProvider { get; private set; }
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var serviceCollection = new ServiceCollection();
ConfigureServices(serviceCollection);
ServiceProvider = serviceCollection.BuildServiceProvider();
Application.Run(ServiceProvider.GetRequiredService<MainForm>());
}
private static void ConfigureServices(ServiceCollection services)
{
// Register your services here
services.AddTransient<ITestService, TestService>();
// Register your forms
services.AddTransient<MainForm>();
}
}
}