51 lines
2.0 KiB
C#
51 lines
2.0 KiB
C#
using GerstITS.Data;
|
|
using GerstITS.Data.EntityFramework;
|
|
using GerstITS.Examples.Transactions.Migrations;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace GerstITS.Examples.Transactions;
|
|
|
|
internal class Program
|
|
{
|
|
#region Methods
|
|
|
|
private static void Main(string[] args)
|
|
{
|
|
using var provider = BuildProvider();
|
|
using var scope = provider.CreateScope();
|
|
|
|
new TransactionRunner(scope.ServiceProvider.GetRequiredService<IRepository>(),
|
|
scope.ServiceProvider.GetRequiredService<ProductDbContext>()).Run();
|
|
}
|
|
|
|
private static ServiceProvider BuildProvider()
|
|
{
|
|
var configuration = new ConfigurationBuilder().SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
|
|
.AddJsonFile("appsettings.json", true, true)
|
|
.Build();
|
|
|
|
var container = new ServiceCollection();
|
|
|
|
container.AddSingleton<IConfiguration>(configuration);
|
|
|
|
// A single configurator instance owns the kept-open SQLite in-memory connection for the whole run.
|
|
container.AddSingleton<SqliteInMemoryDatabaseConfigurator>();
|
|
container.AddSingleton<IDatabaseConfigurator>(services => services.GetRequiredService<SqliteInMemoryDatabaseConfigurator>());
|
|
|
|
container.AddTransient(_ => new DbContextOptionsBuilder<ProductDbContext>().Options);
|
|
container.AddScoped<ProductDbContext>();
|
|
container.AddEntityFrameworkSession<ProductDbContext>();
|
|
|
|
// Provide the repository, sessions, bulk operations and interceptors from the framework.
|
|
new GerstITS.System.Module().RegisterComponents(container);
|
|
new GerstITS.Data.Module().RegisterComponents(container);
|
|
new GerstITS.Data.EntityFramework.Module().RegisterComponents(container);
|
|
|
|
return container.BuildServiceProvider();
|
|
}
|
|
|
|
#endregion
|
|
}
|