-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: clean up of service registration
- Loading branch information
1 parent
a7206e5
commit 08317b6
Showing
49 changed files
with
260 additions
and
161 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...r.Backend/Configuration/AniListOptions.cs → ...Mangarr.Backend/AniList/AniListOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Mangarr.Backend.Configuration; | ||
namespace Mangarr.Backend.AniList; | ||
|
||
public class AniListOptions | ||
{ | ||
|
3 changes: 2 additions & 1 deletion
3
...angarr.Backend/Services/AniListService.cs → ...Mangarr.Backend/AniList/AniListService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Mangarr.Backend.AniList; | ||
|
||
public static class HostExtensions | ||
{ | ||
public static void AddMangarrAniList(this WebApplicationBuilder builder) | ||
{ | ||
builder.Services.Configure<AniListOptions>(builder.Configuration.GetSection(AniListOptions.SECTION)); | ||
builder.Services.AddSingleton<AniListService>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Microsoft.Extensions.Options; | ||
using StackExchange.Redis; | ||
|
||
namespace Mangarr.Backend.Caching; | ||
|
||
public static class HostExtensions | ||
{ | ||
public static void AddMangarrCaching(this WebApplicationBuilder builder) | ||
{ | ||
builder.Services.Configure<RedisOptions>(builder.Configuration.GetSection(RedisOptions.SECTION)); | ||
builder.Services.AddSingleton<CachingService>(); | ||
builder.Services.AddSingleton<IConnectionMultiplexer>(provider => | ||
{ | ||
RedisOptions redisOptions = provider.GetRequiredService<IOptions<RedisOptions>>().Value; | ||
return ConnectionMultiplexer.Connect(redisOptions.Host, | ||
options => { options.Password = redisOptions.Password; }); | ||
}); | ||
builder.Services.AddTransient<IDatabase>( | ||
provider => provider.GetRequiredService<IConnectionMultiplexer>().GetDatabase()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...arr.Backend/Configuration/RedisOptions.cs → src/Mangarr.Backend/Caching/RedisOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Mangarr.Backend.Configuration; | ||
namespace Mangarr.Backend.Caching; | ||
|
||
public class RedisOptions | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Microsoft.Extensions.Options; | ||
using MongoDB.Driver; | ||
|
||
namespace Mangarr.Backend.Database; | ||
|
||
public static class HostExtensions | ||
{ | ||
public static void AddMangarrDatabase(this WebApplicationBuilder builder) | ||
{ | ||
builder.Services.Configure<MongoOptions>(builder.Configuration.GetSection(MongoOptions.SECTION)); | ||
builder.Services.AddTransient<IMongoClient>(provider => | ||
{ | ||
MongoOptions mongoOptions = provider.GetRequiredService<IOptions<MongoOptions>>().Value; | ||
return new MongoClient($"mongodb://{mongoOptions.Username}:{mongoOptions.Password}@{mongoOptions.Host}"); | ||
}); | ||
|
||
builder.Services.AddSingleton<CollectionFactory>(); | ||
builder.Services.AddSingleton(typeof(IMongoCollection<>), typeof(MongoCollection<>)); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...arr.Backend/Configuration/MongoOptions.cs → src/Mangarr.Backend/Database/MongoOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Mangarr.Backend.Configuration; | ||
namespace Mangarr.Backend.Database; | ||
|
||
public class MongoOptions | ||
{ | ||
|
2 changes: 1 addition & 1 deletion
2
src/Mangarr.Backend/Endpoints/Manga/Details/MangaDetailsEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/Mangarr.Backend/Endpoints/Manga/Request/MangaRequestEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
src/Mangarr.Backend/Endpoints/Manga/Search/MangaSearchEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Mangarr.Backend/Endpoints/Manga/Titles/MangaTitlesEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Quartz; | ||
|
||
namespace Mangarr.Backend.Jobs; | ||
|
||
public static class HostExtensions | ||
{ | ||
public static void AddMangarrJobs(this WebApplicationBuilder builder) => | ||
builder.Services | ||
.AddQuartzHostedService(options => | ||
{ | ||
options.AwaitApplicationStarted = true; | ||
options.WaitForJobsToComplete = true; | ||
}) | ||
.AddQuartz(options => | ||
{ | ||
options.AddJob<CacheSourceSchedulerJob>(CacheSourceSchedulerJob.JobKey); | ||
options.AddJob<CacheSourceJob>(CacheSourceJob.JobKey, configure => configure.StoreDurably()) | ||
.UseDefaultThreadPool(3); | ||
options.AddJob<IndexMangaSchedulerJob>(IndexMangaSchedulerJob.JobKey); | ||
options.AddJob<IndexMangaJob>(IndexMangaJob.JobKey, configure => configure.StoreDurably()) | ||
.UseDefaultThreadPool(5); | ||
options.AddJob<DownloadChapterSchedulerJob>(DownloadChapterSchedulerJob.JobKey); | ||
options.AddJob<DownloadChapterJob>(DownloadChapterJob.JobKey, configure => configure.StoreDurably()) | ||
.UseDefaultThreadPool(3); | ||
options.AddTrigger(configure => | ||
{ | ||
configure | ||
.WithIdentity("CacheSourceSchedulerJob") | ||
.WithDescription("Cache enabled sources") | ||
.ForJob(CacheSourceSchedulerJob.JobKey) | ||
.WithCronSchedule("0 0/30 0 ? * * *"); | ||
}); | ||
options.AddTrigger(configure => | ||
{ | ||
configure | ||
.WithIdentity("IndexMangaSchedulerJob") | ||
.WithDescription("Check for new chapters") | ||
.ForJob(IndexMangaSchedulerJob.JobKey) | ||
.WithCronSchedule("0 0 * ? * * *"); | ||
}); | ||
options.AddTrigger(configure => | ||
{ | ||
configure | ||
.WithIdentity("DownloadChapterSchedulerJob") | ||
.WithDescription("Download requested chapters") | ||
.ForJob(DownloadChapterSchedulerJob.JobKey) | ||
.StartNow() | ||
.WithCronSchedule("0 10 * ? * * *"); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Mangarr.Backend.Configuration; | ||
using Microsoft.Extensions.Options; | ||
using Serilog; | ||
using Serilog.Events; | ||
|
||
namespace Mangarr.Backend.Logging; | ||
|
||
public static class HostExtensions | ||
{ | ||
public static void AddMangarrLogging(this WebApplicationBuilder builder) | ||
{ | ||
builder.Services.Configure<SeqOptions>(builder.Configuration.GetSection(SeqOptions.SECTION)); | ||
builder.Services.AddSerilog((provider, configuration) => | ||
{ | ||
SeqOptions seqOptions = provider.GetRequiredService<IOptions<SeqOptions>>().Value; | ||
if (!string.IsNullOrEmpty(seqOptions.Host)) | ||
{ | ||
configuration | ||
.Enrich.WithProperty("Application", "Mangarr") | ||
.Enrich.FromLogContext() | ||
.WriteTo.Seq(seqOptions.Host, | ||
apiKey: seqOptions.Key, | ||
restrictedToMinimumLevel: LogEventLevel.Information); | ||
} | ||
configuration | ||
.WriteTo.Console(LogEventLevel.Debug); | ||
}); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ngarr.Backend/Configuration/SeqOptions.cs → src/Mangarr.Backend/Logging/SeqOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Mangarr.Backend.Configuration; | ||
namespace Mangarr.Backend.Logging; | ||
|
||
public class SeqOptions | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Discord.Webhook; | ||
using Mangarr.Backend.Configuration; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Mangarr.Backend.Notifications; | ||
|
||
public static class HostExtensions | ||
{ | ||
public static void AddMangarrNotifications(this WebApplicationBuilder builder) | ||
{ | ||
builder.Services.Configure<NotificationOptions>(builder.Configuration.GetSection(NotificationOptions.SECTION)); | ||
builder.Services.AddSingleton<NotificationService>(); | ||
builder.Services.AddSingleton<INotificationProcessor, DiscordNotificationProcessor>(); | ||
builder.Services.AddSingleton<DiscordWebhookClient>(provider => | ||
{ | ||
IOptions<NotificationOptions> options = provider.GetRequiredService<IOptions<NotificationOptions>>(); | ||
return options.Value.IsDiscordEnabled ? new DiscordWebhookClient(options.Value.Discord) : null!; | ||
}); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...s/Notifications/INotificationProcessor.cs → ...d/Notifications/INotificationProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...ices/Notifications/NotificationService.cs → ...kend/Notifications/NotificationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.