move classes around, name caches more consistently, add more caches

This commit is contained in:
sam 2024-08-19 16:12:28 +02:00
parent e86b37ce2a
commit e17dcf90a1
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
30 changed files with 443 additions and 51 deletions

View file

@ -1,6 +1,8 @@
using Catalogger.Backend.Bot.Commands;
using Catalogger.Backend.Bot.Responders;
using Catalogger.Backend.Cache;
using Catalogger.Backend.Cache.InMemoryCache;
using Catalogger.Backend.Cache.RedisCache;
using Catalogger.Backend.Database;
using Catalogger.Backend.Database.Queries;
using Catalogger.Backend.Database.Redis;
@ -65,27 +67,34 @@ public static class StartupExtensions
public static IServiceCollection AddCustomServices(this IServiceCollection services) => services
.AddSingleton<IClock>(SystemClock.Instance)
.AddSingleton<GuildCacheService>()
.AddSingleton<RoleCacheService>()
.AddSingleton<ChannelCacheService>()
.AddSingleton<UserCacheService>()
.AddSingleton<GuildCache>()
.AddSingleton<RoleCache>()
.AddSingleton<ChannelCache>()
.AddSingleton<UserCache>()
.AddSingleton<PluralkitApiService>()
.AddScoped<IEncryptionService, EncryptionService>()
.AddScoped<MessageRepository>()
.AddSingleton<WebhookExecutorService>()
.AddSingleton<PkMessageHandler>()
.AddSingleton(InMemoryDataService<Snowflake, ChannelCommandData>.Instance)
.AddHostedService<MetricsCollectionService>();
.AddHostedService<MetricsCollectionService>()
.AddSingleton<GuildFetchService>()
.AddHostedService(serviceProvider => serviceProvider.GetRequiredService<GuildFetchService>());
public static IServiceCollection MaybeAddRedisCaches(this IServiceCollection services, Config config)
{
if (config.Database.Redis == null)
{
return services.AddSingleton<IWebhookCache, InMemoryWebhookCache>();
return services
.AddSingleton<IWebhookCache, InMemoryWebhookCache>()
.AddSingleton<IMemberCache, InMemoryMemberCache>()
.AddSingleton<IInviteCache, InMemoryInviteCache>();
}
return services.AddSingleton<RedisService>()
.AddScoped<IWebhookCache, RedisWebhookCache>();
.AddSingleton<IWebhookCache, RedisWebhookCache>()
.AddSingleton<IMemberCache, RedisMemberCache>()
.AddSingleton<IInviteCache, RedisInviteCache>();
}
public static async Task Initialize(this WebApplication app)