2021-11-29 21:04:15 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
using StackExchange.Redis;
|
|
|
|
|
|
|
|
|
|
namespace Selector.Cache.Extensions
|
|
|
|
|
{
|
|
|
|
|
public static class ServiceExtensions
|
|
|
|
|
{
|
2022-02-18 00:08:42 +00:00
|
|
|
|
public static IServiceCollection AddRedisServices(this IServiceCollection services, string connectionStr)
|
2021-11-29 21:04:15 +00:00
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("> Configuring Redis...");
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(connectionStr))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("> No Redis configuration string provided, exiting...");
|
|
|
|
|
Environment.Exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var connMulti = ConnectionMultiplexer.Connect(connectionStr);
|
|
|
|
|
services.AddSingleton(connMulti);
|
|
|
|
|
services.AddTransient<IDatabaseAsync>(services => services.GetService<ConnectionMultiplexer>().GetDatabase());
|
|
|
|
|
services.AddTransient<ISubscriber>(services => services.GetService<ConnectionMultiplexer>().GetSubscriber());
|
2022-02-18 00:08:42 +00:00
|
|
|
|
|
|
|
|
|
return services;
|
2021-11-29 21:04:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-18 00:08:42 +00:00
|
|
|
|
public static IServiceCollection AddCachingConsumerFactories(this IServiceCollection services)
|
2021-11-29 21:04:15 +00:00
|
|
|
|
{
|
2021-12-04 12:49:09 +00:00
|
|
|
|
services.AddTransient<IAudioFeatureInjectorFactory, CachingAudioFeatureInjectorFactory>();
|
|
|
|
|
services.AddTransient<CachingAudioFeatureInjectorFactory>();
|
2021-11-29 21:04:15 +00:00
|
|
|
|
services.AddTransient<IPlayCounterFactory, PlayCounterCachingFactory>();
|
2021-11-29 21:48:00 +00:00
|
|
|
|
services.AddTransient<PlayCounterCachingFactory>();
|
2021-11-29 21:04:15 +00:00
|
|
|
|
|
|
|
|
|
services.AddTransient<ICacheWriterFactory, CacheWriterFactory>();
|
2021-11-29 21:48:00 +00:00
|
|
|
|
services.AddTransient<CacheWriterFactory>();
|
2021-11-29 21:04:15 +00:00
|
|
|
|
services.AddTransient<IPublisherFactory, PublisherFactory>();
|
2021-11-29 21:48:00 +00:00
|
|
|
|
services.AddTransient<PublisherFactory>();
|
2022-02-18 00:08:42 +00:00
|
|
|
|
|
|
|
|
|
return services;
|
2021-11-29 21:48:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-18 00:08:42 +00:00
|
|
|
|
public static IServiceCollection AddCachingSpotify(this IServiceCollection services)
|
2021-11-29 21:48:00 +00:00
|
|
|
|
{
|
|
|
|
|
services.AddSingleton<AudioFeaturePuller>();
|
2022-02-18 00:08:42 +00:00
|
|
|
|
|
|
|
|
|
return services;
|
2021-11-29 21:04:15 +00:00
|
|
|
|
}
|
2021-11-30 20:38:26 +00:00
|
|
|
|
|
2022-02-18 00:08:42 +00:00
|
|
|
|
public static IServiceCollection AddCachingLastFm(this IServiceCollection services)
|
2021-11-30 20:38:26 +00:00
|
|
|
|
{
|
|
|
|
|
services.AddSingleton<PlayCountPuller>();
|
2022-02-18 00:08:42 +00:00
|
|
|
|
|
|
|
|
|
return services;
|
2021-11-30 20:38:26 +00:00
|
|
|
|
}
|
2021-11-29 21:04:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|