60 lines
2.1 KiB
C#
60 lines
2.1 KiB
C#
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 IServiceCollection 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());
|
|
|
|
return services;
|
|
}
|
|
|
|
public static IServiceCollection AddCachingConsumerFactories(this IServiceCollection services)
|
|
{
|
|
services.AddTransient<IAudioFeatureInjectorFactory, CachingAudioFeatureInjectorFactory>();
|
|
services.AddTransient<CachingAudioFeatureInjectorFactory>();
|
|
services.AddTransient<IPlayCounterFactory, PlayCounterCachingFactory>();
|
|
services.AddTransient<PlayCounterCachingFactory>();
|
|
|
|
services.AddTransient<ICacheWriterFactory, CacheWriterFactory>();
|
|
services.AddTransient<CacheWriterFactory>();
|
|
services.AddTransient<IPublisherFactory, PublisherFactory>();
|
|
services.AddTransient<PublisherFactory>();
|
|
|
|
return services;
|
|
}
|
|
|
|
public static IServiceCollection AddCachingSpotify(this IServiceCollection services)
|
|
{
|
|
services.AddSingleton<AudioFeaturePuller>();
|
|
|
|
return services;
|
|
}
|
|
|
|
public static IServiceCollection AddCachingLastFm(this IServiceCollection services)
|
|
{
|
|
services.AddSingleton<PlayCountPuller>();
|
|
|
|
return services;
|
|
}
|
|
}
|
|
}
|