55using Microsoft . AspNetCore . Http ;
66using Microsoft . AspNetCore . Http . Features ;
77using Microsoft . AspNetCore . Server . Kestrel . Core ;
8+ using Microsoft . EntityFrameworkCore ;
89using Microsoft . Extensions . Configuration ;
910using Microsoft . Extensions . DependencyInjection ;
1011using Microsoft . Extensions . Hosting ;
@@ -84,6 +85,9 @@ public void ConfigureServices(IServiceCollection services)
8485 var useEmbeddedDatabase = Configuration . GetValue < bool > ( "USE_EMBEDDED_DATABASE" , false ) ||
8586 Environment . GetEnvironmentVariable ( "USE_EMBEDDED_DATABASE" ) == "true" ;
8687
88+ var useSqlDatabase = Configuration . GetValue < bool > ( "USE_SQL_DATABASE" , false ) ||
89+ Environment . GetEnvironmentVariable ( "USE_SQL_DATABASE" ) == "true" ;
90+
8791 if ( useEmbeddedDatabase )
8892 {
8993 // Use LiteDB for self-contained operation
@@ -99,11 +103,19 @@ public void ConfigureServices(IServiceCollection services)
99103 services . AddScoped < IDownloadAnalyticsRepository > ( provider =>
100104 new Services . Repositories . LiteDbDownloadAnalyticsRepository ( databasePath ) ) ;
101105 }
106+ else if ( useSqlDatabase )
107+ {
108+ // Use SQL database for operation
109+ services . AddDbContext < FilesDbContext > ( options => options . UseSqlite ( "Data Source=database.db" ) ) ;
110+ services . AddScoped < IStorageRepository , SqlStorageRepository > ( ) ;
111+ services . AddScoped < IFileDetailsRepository , SqlFileDetailsRepository > ( ) ;
112+ services . AddScoped < IDownloadAnalyticsRepository , SqlDbDownloadAnalyticsRepository > ( ) ;
113+ }
102114 else
103115 {
104116 // Use MongoDB for traditional operation
105- services . AddScoped < IStorageRepository , StorageRepository > ( ) ;
106- services . AddScoped < IFileDetailsRepository , FileDetailsRepository > ( ) ;
117+ services . AddScoped < IStorageRepository , MongoStorageRepository > ( ) ;
118+ services . AddScoped < IFileDetailsRepository , MongoFileDetailsRepository > ( ) ;
107119 services . AddScoped < IDownloadAnalyticsRepository , Services . Repositories . MongoDbDownloadAnalyticsRepository > ( ) ;
108120 }
109121
0 commit comments