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
|
|
|
|
|
{
|
|
|
|
|
public static void AddRedisServices(this IServiceCollection services, string connectionStr)
|
|
|
|
|
{
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AddCachingConsumerFactories(this IServiceCollection services)
|
|
|
|
|
{
|
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>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AddCachingSpotify(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddSingleton<AudioFeaturePuller>();
|
2021-11-29 21:04:15 +00:00
|
|
|
|
}
|
2021-11-30 20:38:26 +00:00
|
|
|
|
|
|
|
|
|
public static void AddCachingLastFm(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddSingleton<PlayCountPuller>();
|
|
|
|
|
}
|
2021-11-29 21:04:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|