| | | 1 | | using LifeChart.Application.Interfaces; |
| | | 2 | | using LifeChart.Application.Settings; |
| | | 3 | | using LifeChart.Domain.Entries; |
| | | 4 | | using LifeChart.Domain.Medications; |
| | | 5 | | using LifeChart.Infrastructure.Backup; |
| | | 6 | | using LifeChart.Infrastructure.CrisisResources; |
| | | 7 | | using LifeChart.Infrastructure.Pdf; |
| | | 8 | | using LifeChart.Infrastructure.Persistence; |
| | | 9 | | using LifeChart.Infrastructure.Repositories; |
| | | 10 | | using Microsoft.EntityFrameworkCore; |
| | | 11 | | using Microsoft.Extensions.DependencyInjection; |
| | | 12 | | |
| | | 13 | | namespace LifeChart.Infrastructure; |
| | | 14 | | |
| | | 15 | | public static class DependencyInjection |
| | | 16 | | { |
| | | 17 | | public static IServiceCollection AddInfrastructure(this IServiceCollection services) |
| | | 18 | | { |
| | 0 | 19 | | var dbPath = Path.Combine( |
| | 0 | 20 | | Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), |
| | 0 | 21 | | "LifeChart", |
| | 0 | 22 | | "lifechart.db"); |
| | | 23 | | |
| | 0 | 24 | | Directory.CreateDirectory(Path.GetDirectoryName(dbPath)!); |
| | | 25 | | |
| | 0 | 26 | | services.AddDbContext<LifeChartDbContext>(options => |
| | 0 | 27 | | options.UseSqlite($"Data Source={dbPath}")); |
| | | 28 | | |
| | 0 | 29 | | services.AddScoped<IDailyEntryRepository, DailyEntryRepository>(); |
| | 0 | 30 | | services.AddScoped<IMedicationRepository, MedicationRepository>(); |
| | | 31 | | |
| | | 32 | | // PDF |
| | 0 | 33 | | services.AddScoped<IPdfRenderer, PdfRenderer>(); |
| | | 34 | | |
| | | 35 | | // Backup providers |
| | 0 | 36 | | services.AddSingleton<LocalExportProvider>(); |
| | 0 | 37 | | services.AddHttpClient<NextcloudBackupProvider>(); |
| | | 38 | | #if GOOGLE_SERVICES |
| | | 39 | | services.AddHttpClient<GoogleDriveBackupProvider>(); |
| | | 40 | | #endif |
| | 0 | 41 | | services.AddScoped<IBackupProvider>(sp => |
| | 0 | 42 | | { |
| | 0 | 43 | | var settings = sp.GetRequiredService<ISettingsService>().Load(); |
| | 0 | 44 | | return settings.BackupProvider switch |
| | 0 | 45 | | { |
| | 0 | 46 | | #if GOOGLE_SERVICES |
| | 0 | 47 | | CloudProvider.GoogleDrive => |
| | 0 | 48 | | sp.GetRequiredService<GoogleDriveBackupProvider>(), |
| | 0 | 49 | | #endif |
| | 0 | 50 | | CloudProvider.Nextcloud => |
| | 0 | 51 | | sp.GetRequiredService<NextcloudBackupProvider>(), |
| | 0 | 52 | | _ => sp.GetRequiredService<LocalExportProvider>() |
| | 0 | 53 | | }; |
| | 0 | 54 | | }); |
| | | 55 | | |
| | | 56 | | // Crisis resources |
| | 0 | 57 | | services.AddHttpClient<FindAHelplineService>(); |
| | 0 | 58 | | services.AddSingleton<StaticCrisisResourceService>(); |
| | 0 | 59 | | services.AddScoped<ICrisisResourceService, HybridCrisisResourceService>(); |
| | | 60 | | |
| | 0 | 61 | | return services; |
| | | 62 | | } |
| | | 63 | | } |