You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ombi/src/Ombi.DependencyInjection/IocExtensions.cs

95 lines
3.7 KiB

using System.Diagnostics.CodeAnalysis;
8 years ago
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;
8 years ago
using Ombi.Api.TheMovieDb;
8 years ago
using Ombi.Api.Trakt;
8 years ago
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;
8 years ago
using Ombi.Schedule;
using Ombi.Schedule.Jobs;
using Ombi.Settings.Settings;
using Ombi.Store.Context;
using Ombi.Store.Repository;
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();
8 years ago
services.RegisterJobs();
}
public static void RegisterEngines(this IServiceCollection services)
{
8 years ago
services.AddTransient<IMovieEngine, MovieSearchEngine>();
8 years ago
services.AddTransient<IMovieRequestEngine, MovieRequestEngine>();
services.AddTransient<ITvRequestEngine, TvRequestEngine>();
services.AddTransient<ITvSearchEngine, TvSearchEngine>();
}
public static void RegisterApi(this IServiceCollection services)
{
8 years ago
services.AddTransient<IMovieDbApi, Api.TheMovieDb.TheMovieDbApi>();
services.AddTransient<IPlexApi, PlexApi>();
services.AddTransient<IEmbyApi, EmbyApi>();
services.AddTransient<ISonarrApi, SonarrApi>();
8 years ago
services.AddTransient<ITvMazeApi, TvMazeApi>();
8 years ago
services.AddTransient<ITraktApi, TraktApi>();
}
public static void RegisterStore(this IServiceCollection services)
{
services.AddEntityFrameworkSqlite().AddDbContext<OmbiContext>();
services.AddScoped<IOmbiContext, OmbiContext>();
services.AddTransient<IRequestRepository, RequestJsonRepository>();
services.AddTransient<ISettingsRepository, SettingsJsonRepository>();
services.AddTransient<IUserRepository, UserRepository>();
services.AddTransient<ISettingsResolver, SettingsResolver>();
services.AddTransient<IPlexContentRepository, PlexContentRepository>();
services.AddTransient(typeof(ISettingsService<>), typeof(SettingsServiceV2<>));
}
public static void RegisterServices(this IServiceCollection services)
{
8 years ago
services.AddTransient<IRequestServiceMain, RequestService>();
services.AddTransient(typeof(IRequestService<>), typeof(JsonRequestService<>));
services.AddSingleton<INotificationService, NotificationService>();
}
8 years ago
public static void RegisterJobs(this IServiceCollection services)
8 years ago
{
services.AddTransient<IPlexContentCacher, PlexContentCacher>();
services.AddTransient<IJobSetup, JobSetup>();
8 years ago
}
public static void RegisterIdentity(this IServiceCollection services)
8 years ago
{
services.AddTransient<IUserIdentityManager, UserIdentityManager>();
8 years ago
services.AddAuthorization(auth =>
{
auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder()
.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
.RequireAuthenticatedUser().Build());
});
}
}
}