< Summary

Information
Class: Anichron.Worker.Infrastructure.WorkerServiceCollectionExtensions
Assembly: Anichron.Worker
File(s): /home/runner/work/anichron/anichron/src/Anichron.Worker/Infrastructure/WorkerServiceCollectionExtensions.cs
Tag: 228_36821334185
Line coverage
79%
Covered lines: 43
Uncovered lines: 11
Coverable lines: 54
Total lines: 97
Line coverage: 79.6%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddWorkerCoreServices(...)100%11100%
AddWorkerDataServices(...)100%210%
AddIngestionServices(...)100%11100%
AddVideoProxyServices(...)100%11100%
AddImageProxyServices(...)100%11100%
AddWorkerHostedServices(...)100%11100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.Worker/Infrastructure/WorkerServiceCollectionExtensions.cs

#LineLine coverage
 1using Anichron.Core;
 2using Anichron.Core.Data;
 3using Anichron.Core.Data.Repository;
 4using Anichron.Infrastructure.Configuration;
 5using Anichron.Worker.Crawling;
 6using Anichron.Worker.Ingestion;
 7using Anichron.Worker.Ingestion.Middlewares;
 8using Anichron.Worker.Ingestion.Pipeline;
 9using Anichron.Worker.Ingestion.Proxy;
 10using Anichron.Worker.Maintenance;
 11using Anichron.Worker.Settings;
 12using Anichron.Worker.Startup;
 13using Microsoft.EntityFrameworkCore;
 14using NodaTime;
 15using System.IO.Abstractions;
 16using CrawlingWorker = Anichron.Worker.Crawling.Worker;
 17
 18namespace Anichron.Worker.Infrastructure;
 19
 20internal static class WorkerServiceCollectionExtensions
 21{
 22    extension(IServiceCollection services)
 23    {
 24        internal IServiceCollection AddWorkerCoreServices()
 325        {
 326            services.AddOptions<WorkerSettings>()
 327                .BindConfiguration("Worker")
 328                .ValidateDataAnnotations()
 329                .ValidateOnStart();
 330            services.AddSingleton<IGuidFactory, TimeOrderedGuidFactory>();
 331            services.AddSingleton<IClock>(SystemClock.Instance);
 332            services.AddSingleton<WorkerState>();
 333            return services;
 34        }
 35
 36        internal IServiceCollection AddWorkerDataServices(IConfiguration configuration)
 037        {
 038            var connectionString = DatabaseConfiguration.GetConnectionString(configuration, new FileSystem());
 039            services.AddDbContext<AnichronDbContext>(options =>
 040                options.UseNpgsql(connectionString, o => o.UseNodaTime()));
 041            services.AddScoped<IUserRepository, EfUserRepository>();
 042            services.AddScoped<IUserStorageConfigRepository, EfUserStorageConfigRepository>();
 043            services.AddScoped<IRefreshTokenRepository, EfRefreshTokenRepository>();
 044            services.AddScoped<IMediaAssetRepository, EfMediaAssetRepository>();
 045            services.AddScoped<IDatabaseMigrator, EfDatabaseMigrator>();
 046            services.AddScoped<IUnitOfWork>(sp => sp.GetRequiredService<AnichronDbContext>());
 047            return services;
 48        }
 49
 50        internal IServiceCollection AddIngestionServices()
 751        {
 752            services.AddSingleton<IFileSystem, FileSystem>();
 753            services.AddSingleton<ILivePhotoLinker, LivePhotoLinker>();
 754            services.AddSingleton<IFileIngestionPipeline, FileIngestionPipeline>();
 755            services.AddSingleton<IProxyDirectoryStrategy, TwoLevelHexShardStrategy>();
 756            services.AddSingleton<ProxyStagingWriter>();
 757            services.AddImageProxyServices();
 758            services.AddVideoProxyServices();
 759            services.AddScoped<IIngestionMiddleware, LoggingMiddleware>();
 760            services.AddScoped<IIngestionMiddleware, ContentHashingMiddleware>();
 761            services.AddScoped<IIngestionMiddleware, IdempotencyCheckMiddleware>();
 762            services.AddScoped<IIngestionMiddleware, ExifExtractionMiddleware>();
 763            services.AddScoped<IIngestionMiddleware, ImageProxyMiddleware>();
 764            services.AddScoped<IIngestionMiddleware, VideoProxyMiddleware>();
 765            services.AddScoped<IIngestionMiddleware, PersistenceMiddleware>();
 766            services.AddScoped<IIngestionPipelineRunner, IngestionPipelineRunner>();
 767            return services;
 68        }
 69
 70        // void, not IServiceCollection: these two are private and both call sites above invoke
 71        // them as statements, so the fluent return was never consumed. The internal members keep
 72        // returning IServiceCollection because they are part of the chainable surface.
 73        private void AddVideoProxyServices()
 774        {
 775            services.AddSingleton<IProcessLauncher, SystemProcessLauncher>();
 776            services.AddSingleton<IVideoProcessor, FfmpegVideoProcessor>();
 777            services.AddSingleton<IVideoProxyGenerator, Video720PGenerator>();
 778        }
 79
 80        private void AddImageProxyServices()
 781        {
 782            services.AddSingleton<IImageProcessor, ImageSharpProcessor>();
 783            services.AddSingleton<IImageProxyGenerator, ThumbnailGenerator>();
 784            services.AddSingleton<IImageProxyGenerator, FullPreviewGenerator>();
 785            services.AddSingleton<IImageProxyGenerator, BlurhashGenerator>();
 786        }
 87
 88        internal IServiceCollection AddWorkerHostedServices()
 189        {
 190            services.AddHostedService<DatabaseMigratorService>();
 191            services.AddHostedService<WorkerInitializer>();
 192            services.AddHostedService<TokenCleanupService>();
 193            services.AddHostedService<CrawlingWorker>();
 194            return services;
 95        }
 96    }
 97}