< Summary

Information
Class: LifeChart.Infrastructure.DependencyInjection
Assembly: LifeChart.Infrastructure
File(s): /home/runner/work/lifechart/lifechart/src/LifeChart.Infrastructure/DependencyInjection.cs
Tag: 113_29159449707
Line coverage
0%
Covered lines: 0
Uncovered lines: 30
Coverable lines: 30
Total lines: 63
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddInfrastructure(...)0%620%

File(s)

/home/runner/work/lifechart/lifechart/src/LifeChart.Infrastructure/DependencyInjection.cs

#LineLine coverage
 1using LifeChart.Application.Interfaces;
 2using LifeChart.Application.Settings;
 3using LifeChart.Domain.Entries;
 4using LifeChart.Domain.Medications;
 5using LifeChart.Infrastructure.Backup;
 6using LifeChart.Infrastructure.CrisisResources;
 7using LifeChart.Infrastructure.Pdf;
 8using LifeChart.Infrastructure.Persistence;
 9using LifeChart.Infrastructure.Repositories;
 10using Microsoft.EntityFrameworkCore;
 11using Microsoft.Extensions.DependencyInjection;
 12
 13namespace LifeChart.Infrastructure;
 14
 15public static class DependencyInjection
 16{
 17    public static IServiceCollection AddInfrastructure(this IServiceCollection services)
 18    {
 019        var dbPath = Path.Combine(
 020            Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
 021            "LifeChart",
 022            "lifechart.db");
 23
 024        Directory.CreateDirectory(Path.GetDirectoryName(dbPath)!);
 25
 026        services.AddDbContext<LifeChartDbContext>(options =>
 027            options.UseSqlite($"Data Source={dbPath}"));
 28
 029        services.AddScoped<IDailyEntryRepository, DailyEntryRepository>();
 030        services.AddScoped<IMedicationRepository, MedicationRepository>();
 31
 32        // PDF
 033        services.AddScoped<IPdfRenderer, PdfRenderer>();
 34
 35        // Backup providers
 036        services.AddSingleton<LocalExportProvider>();
 037        services.AddHttpClient<NextcloudBackupProvider>();
 38#if GOOGLE_SERVICES
 39        services.AddHttpClient<GoogleDriveBackupProvider>();
 40#endif
 041        services.AddScoped<IBackupProvider>(sp =>
 042        {
 043            var settings = sp.GetRequiredService<ISettingsService>().Load();
 044            return settings.BackupProvider switch
 045            {
 046#if GOOGLE_SERVICES
 047                CloudProvider.GoogleDrive =>
 048                    sp.GetRequiredService<GoogleDriveBackupProvider>(),
 049#endif
 050                CloudProvider.Nextcloud =>
 051                    sp.GetRequiredService<NextcloudBackupProvider>(),
 052                _ => sp.GetRequiredService<LocalExportProvider>()
 053            };
 054        });
 55
 56        // Crisis resources
 057        services.AddHttpClient<FindAHelplineService>();
 058        services.AddSingleton<StaticCrisisResourceService>();
 059        services.AddScoped<ICrisisResourceService, HybridCrisisResourceService>();
 60
 061        return services;
 62    }
 63}