Selector/Selector.Cache/Extensions/ServiceExtensions.cs

60 lines
2.1 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 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>();
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>();
return services;
2021-11-29 21:48:00 +00:00
}
public static IServiceCollection AddCachingSpotify(this IServiceCollection services)
2021-11-29 21:48:00 +00:00
{
services.AddSingleton<AudioFeaturePuller>();
return services;
}
public static IServiceCollection AddCachingLastFm(this IServiceCollection services)
{
services.AddSingleton<PlayCountPuller>();
return services;
}
}
}