| 
									
										
										
										
											2024-12-08 15:07:25 +01:00
										 |  |  | using Npgsql; | 
					
						
							| 
									
										
										
										
											2024-10-30 15:35:23 +01:00
										 |  |  | using Serilog; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Foxnouns.Backend.Database; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public static class DatabaseServiceExtensions | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public static IServiceCollection AddFoxnounsDatabase( | 
					
						
							|  |  |  |         this IServiceCollection serviceCollection, | 
					
						
							|  |  |  |         Config config | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-12-08 15:07:25 +01:00
										 |  |  |         NpgsqlDataSource dataSource = DatabaseContext.BuildDataSource(config); | 
					
						
							|  |  |  |         ILoggerFactory loggerFactory = new LoggerFactory().AddSerilog(dispose: false); | 
					
						
							| 
									
										
										
										
											2024-10-30 15:35:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         serviceCollection.AddDbContext<DatabaseContext>(options => | 
					
						
							|  |  |  |             DatabaseContext.BuildOptions(options, dataSource, loggerFactory) | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return serviceCollection; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |