using System.Diagnostics.CodeAnalysis; using System.Net; using System.Security.Principal; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Ombi.Api.External.NotificationServices.Discord; using Ombi.Api.External.MediaServers.Emby; using Ombi.Api.External.MediaServers.Jellyfin; using Ombi.Api.External.MediaServers.Plex; using Ombi.Api.External.ExternalApis.Radarr; using Ombi.Api.External.ExternalApis.Sonarr; using Ombi.Api.External.ExternalApis.TheMovieDb; using Ombi.Api.External.ExternalApis.Trakt; using Ombi.Api.External.ExternalApis.TvMaze; using Ombi.Core; using Ombi.Core.Engine; using Ombi.Core.Engine.Interfaces; using Ombi.Core.Models.Requests; using Ombi.Core.Notifications; using Ombi.Core.Rule; using Ombi.Core.Settings; using Ombi.Notifications; using Ombi.Schedule; using Ombi.Schedule.Jobs; using Ombi.Settings.Settings; using Ombi.Store.Repository; using Ombi.Notifications.Agents; using Ombi.Schedule.Jobs.Radarr; using Ombi.Api; using Ombi.Api.External.ExternalApis.CouchPotato; using Ombi.Api.External.ExternalApis.DogNzb; using Ombi.Api.External.ExternalApis.FanartTv; using Ombi.Api.External.ExternalApis.Github; using Ombi.Api.External.NotificationServices.Gotify; using Ombi.Api.External.NotificationServices.Ntfy; using Ombi.Api.External.NotificationServices.GroupMe; using Ombi.Api.External.NotificationServices.Webhook; using Ombi.Api.External.ExternalApis.Lidarr; using Ombi.Api.External.NotificationServices.Mattermost; using Ombi.Api.External.NotificationServices.Notifications; using Ombi.Api.External.NotificationServices.Pushbullet; using Ombi.Api.External.NotificationServices.Pushover; using Ombi.Api.External.ExternalApis.Service; using Ombi.Api.External.ExternalApis.SickRage; using Ombi.Api.External.NotificationServices.Slack; using Ombi.Core.Rule.Interfaces; using Ombi.Core.Senders; using Ombi.Helpers; using Ombi.Schedule.Jobs.Couchpotato; using Ombi.Schedule.Jobs.Emby; using Ombi.Schedule.Jobs.Jellyfin; using Ombi.Schedule.Jobs.Ombi; using Ombi.Schedule.Jobs.Plex; using Ombi.Schedule.Jobs.Sonarr; using Ombi.Store.Repository.Requests; using Ombi.Updater; using Ombi.Api.External.NotificationServices.Telegram; using Ombi.Core.Authentication; using Ombi.Core.Engine.Demo; using Ombi.Core.Engine.V2; using Ombi.Core.Processor; using Ombi.Schedule.Jobs.Lidarr; using Ombi.Schedule.Jobs.Plex.Interfaces; using Ombi.Schedule.Jobs.SickRage; using Ombi.Schedule.Processor; using Quartz.Spi; using Ombi.Api.External.ExternalApis.MusicBrainz; using Ombi.Api.External.NotificationServices.Twilio; using Ombi.Api.External.NotificationServices.CloudService; using Ombi.Api.External.ExternalApis.RottenTomatoes; using System.Net.Http; using Microsoft.Extensions.Logging; using Ombi.Core.Services; using Ombi.Core.Helpers; using Ombi.Hubs; using Hqub.MusicBrainz.API; namespace Ombi.DependencyInjection { [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] public static class IocExtensions { public static void RegisterApplicationDependencies(this IServiceCollection services) { services.RegisterEngines(); services.RegisterEnginesV2(); services.RegisterApi(); services.RegisterHttp(); services.RegisterServices(); services.RegisterStore(); services.RegisterJobs(); services.RegisterHubs(); } public static void RegisterEngines(this IServiceCollection services) { services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); } public static void RegisterEnginesV2(this IServiceCollection services) { services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); } public static void RegisterHttp(this IServiceCollection services) { var runtimeVersion = AssemblyHelper.GetRuntimeVersion(); services.AddSingleton(); services.AddScoped(sp => sp.GetService().HttpContext.User); // HttpContext User is null for background jobs services.AddScoped(sp => new CurrentUser(sp.GetService()?.HttpContext?.User ?? null, sp.GetService())); services.AddHttpClient("OmbiClient", client => { client.DefaultRequestHeaders.Add("User-Agent", $"Ombi/{runtimeVersion} (https://ombi.io/)"); }).ConfigurePrimaryHttpMessageHandler(() => { var httpClientHandler = new HttpClientHandler { // Some upstream APIs (notably TheMovieDb behind its CDN) may return // gzip/brotli-encoded responses even when no Accept-Encoding header is // sent. Without automatic decompression the raw compressed bytes are // handed to ReadAsStringAsync, producing UTF-8 replacement characters // (U+FFFD) and a Newtonsoft.Json "Unexpected character ... line 0, // position 0" failure (intermittent, often seen under Docker on Linux). AutomaticDecompression = DecompressionMethods.All, }; httpClientHandler.ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true; return httpClientHandler; }); } public static void RegisterApi(this IServiceCollection services) { services.AddScoped(s => new Api.Api( s.GetRequiredService>(), s.GetRequiredService().CreateClient("OmbiClient"), s.GetRequiredService(), s.GetRequiredService())); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(_ => new MusicBrainzClient()); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); } public static void RegisterStore(this IServiceCollection services) { //services.AddDbContext(); //services.AddDbContext(); //services.AddDbContext(); //services.AddScoped(); // https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6 //services.AddScoped(); // https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6 //services.AddScoped(); // https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6 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(typeof(ISettingsService<>), typeof(SettingsService<>)); services.AddScoped(typeof(IRepository<>), typeof(Repository<>)); services.AddScoped(typeof(IExternalRepository<>), typeof(ExternalRepository<>)); } public static void RegisterServices(this IServiceCollection services) { services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddSingleton(); services.AddSingleton(); services.AddScoped(); services.AddScoped(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddScoped(); services.AddTransient(); services.AddTransient(); services.AddScoped(); services.AddSingleton(); services.AddSingleton(); } public static void RegisterJobs(this IServiceCollection services) { services.AddSingleton(); services.AddSingleton(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); } public static void RegisterHubs(this IServiceCollection services) { services.AddScoped(); } } }