Selector/Selector.Cache/Extensions/ServiceExtensions.cs

52 lines
2.0 KiB
C#
Raw Normal View History

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)
{
services.AddTransient<IAudioFeatureInjectorFactory, CachingAudioFeatureInjectorFactory>();
services.AddTransient<CachingAudioFeatureInjectorFactory>();
services.AddTransient<IPlayCounterFactory, PlayCounterCachingFactory>();
2021-11-29 21:48:00 +00:00
services.AddTransient<PlayCounterCachingFactory>();
services.AddTransient<ICacheWriterFactory, CacheWriterFactory>();
2021-11-29 21:48:00 +00:00
services.AddTransient<CacheWriterFactory>();
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>();
}
public static void AddCachingLastFm(this IServiceCollection services)
{
services.AddSingleton<PlayCountPuller>();
}
}
}