using System.IO.Abstractions; using API.Data; using API.Helpers; using API.Interfaces; using API.Interfaces.Services; using API.Services; using API.Services.Tasks; using API.SignalR.Presence; using Kavita.Common; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace API.Extensions { public static class ApplicationServiceExtensions { public static void AddApplicationServices(this IServiceCollection services, IConfiguration config, IWebHostEnvironment env) { services.AddAutoMapper(typeof(AutoMapperProfiles).Assembly); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddSqLite(config, env); services.AddLogging(config); services.AddSignalR(opt => opt.EnableDetailedErrors = true); } private static void AddSqLite(this IServiceCollection services, IConfiguration config, IWebHostEnvironment env) { services.AddDbContext(options => { options.UseSqlite(config.GetConnectionString("DefaultConnection")); options.EnableSensitiveDataLogging(env.IsDevelopment() || Configuration.LogLevel.Equals("Debug")); }); } private static void AddLogging(this IServiceCollection services, IConfiguration config) { services.AddLogging(loggingBuilder => { var loggingSection = config.GetSection("Logging"); loggingBuilder.AddFile(loggingSection); }); } } }