using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.DependencyInjection; using Ombi.Api.Emby; using Ombi.Api.Plex; using Ombi.Api.Sonarr; using Ombi.Api.TheMovieDb; using Ombi.Api.Trakt; using Ombi.Api.TvMaze; using Ombi.Core; using Ombi.Core.Engine; using Ombi.Core.Engine.Interfaces; using Ombi.Core.IdentityResolver; using Ombi.Core.Models.Requests; using Ombi.Core.Requests.Models; using Ombi.Core.Settings; using Ombi.Notifications; using Ombi.Schedule; using Ombi.Schedule.Jobs; using Ombi.Settings.Settings; using Ombi.Store.Context; using Ombi.Store.Repository; using Ombi.Core.Rules; namespace Ombi.DependencyInjection { [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] public static class IocExtensions { public static void RegisterDependencies(this IServiceCollection services) { services.RegisterEngines(); services.RegisterApi(); services.RegisterServices(); services.RegisterStore(); services.RegisterIdentity(); services.RegisterJobs(); } public static void RegisterEngines(this IServiceCollection services) { services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddSingleton(); } public static void RegisterApi(this IServiceCollection services) { services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); } public static void RegisterStore(this IServiceCollection services) { services.AddEntityFrameworkSqlite().AddDbContext(); services.AddScoped(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(typeof(ISettingsService<>), typeof(SettingsServiceV2<>)); } public static void RegisterServices(this IServiceCollection services) { services.AddTransient(); services.AddTransient(typeof(IRequestService<>), typeof(JsonRequestService<>)); services.AddSingleton(); } public static void RegisterJobs(this IServiceCollection services) { services.AddTransient(); services.AddTransient(); } public static void RegisterIdentity(this IServiceCollection services) { services.AddTransient(); services.AddAuthorization(auth => { auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder() .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser().Build()); }); } } }