diff --git a/src/HeartTrackAPI/AppBootstrap.cs b/src/HeartTrackAPI/AppBootstrap.cs index ab8952e..2f75fb0 100644 --- a/src/HeartTrackAPI/AppBootstrap.cs +++ b/src/HeartTrackAPI/AppBootstrap.cs @@ -58,8 +58,9 @@ public class AppBootstrap(IConfiguration configuration) Console.WriteLine("======================"); Console.WriteLine($"server={HOST};port={PORT};database={DATABASE};user={USERNAME};password={PASSWORD}"); Console.WriteLine(connectionString); - - services.AddSingleton( new DbDataManager(connectionString)); + services.AddDbContext(options => + options.UseSqlite(connectionString), ServiceLifetime.Singleton); + services.AddSingleton(provider => new DbDataManager(provider.GetRequiredService())); break; default: diff --git a/src/Model2Entities/DbDataManager.cs b/src/Model2Entities/DbDataManager.cs index fd7661e..6384b43 100644 --- a/src/Model2Entities/DbDataManager.cs +++ b/src/Model2Entities/DbDataManager.cs @@ -18,11 +18,8 @@ public partial class DbDataManager: IDataManager DbContext = dbContext; Console.WriteLine("Contexttttttttt"); Console.WriteLine($"Database created Context: {DbContext.Database.EnsureCreated()}"); - DbContext.Database.EnsureCreated(); - Console.WriteLine($"Database created Context: {DbContext.Database.EnsureCreated()}"); ActivityRepo = new ActivityRepository(this); UserRepo = new UserRepository(this); - DbContext.Database.EnsureCreated(); ActivityMapper.Reset(); // Faire pour les autres reset() des autres mappers } @@ -30,14 +27,12 @@ public partial class DbDataManager: IDataManager public DbDataManager(string dbPlatformPath) : this(new HeartTrackContext(dbPlatformPath)) { - DbContext.Database.EnsureCreated(); Console.WriteLine($"Database created String: {DbContext.Database.EnsureCreated()}"); } public DbDataManager() { DbContext = new HeartTrackContext(); - DbContext.Database.EnsureCreated(); Console.WriteLine($"Database created None: {DbContext.Database.EnsureCreated()}"); ActivityRepo = new ActivityRepository(this); UserRepo= new UserRepository(this);