diff --git a/Selector.CLI/DbWatcherService.cs b/Selector.CLI/DbWatcherService.cs index ab31f95..7f57d5f 100644 --- a/Selector.CLI/DbWatcherService.cs +++ b/Selector.CLI/DbWatcherService.cs @@ -22,8 +22,7 @@ namespace Selector.CLI { private const int PollPeriod = 1000; - private readonly ILogger Logger; - private readonly ILoggerFactory LoggerFactory; + private readonly ILogger Logger; private readonly IServiceProvider ServiceProvider; private readonly IWatcherFactory WatcherFactory; @@ -48,11 +47,10 @@ namespace Selector.CLI IPublisherFactory publisherFactory, ICacheWriterFactory cacheWriterFactory, - ILoggerFactory loggerFactory, + ILogger logger, IServiceProvider serviceProvider ) { - Logger = loggerFactory.CreateLogger(); - LoggerFactory = loggerFactory; + Logger = logger; ServiceProvider = serviceProvider; WatcherFactory = watcherFactory; diff --git a/Selector.CLI/Program.cs b/Selector.CLI/Program.cs index 30b26ef..7a324c1 100644 --- a/Selector.CLI/Program.cs +++ b/Selector.CLI/Program.cs @@ -1,17 +1,17 @@ using System; using System.Threading.Tasks; using System.CommandLine; -using System.CommandLine.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Configuration; using Microsoft.EntityFrameworkCore; using NLog.Extensions.Logging; +using Selector.Extensions; using Selector.Model; using Selector.Cache; using Selector.Cache.Extensions; + using IF.Lastfm.Core.Api; namespace Selector.CLI @@ -54,9 +54,7 @@ namespace Selector.CLI { Console.WriteLine("> Adding Last.fm credentials..."); - var lastAuth = new LastAuth(config.LastfmClient, config.LastfmSecret); - services.AddSingleton(lastAuth); - services.AddTransient(sp => new LastfmClient(sp.GetService())); + services.AddLastFm(config.LastfmClient, config.LastfmSecret); } else { @@ -101,14 +99,12 @@ namespace Selector.CLI Console.WriteLine("> Adding Services..."); // SERVICES + services.AddConsumerFactories(); services.AddCachingConsumerFactories(); + services.AddWatcher(); - services.AddSingleton(); - services.AddSingleton(); - // For generating spotify clients - //services.AddSingleton(); - services.AddSingleton(); - + services.AddSpotify(); + services.AddCachingSpotify(); ConfigureLastFm(config, services); ConfigureDb(config, services); diff --git a/Selector.Cache/Consumer/PlayCounterCaching.cs b/Selector.Cache/Consumer/PlayCounterCaching.cs index 7fb4887..1df8cea 100644 --- a/Selector.Cache/Consumer/PlayCounterCaching.cs +++ b/Selector.Cache/Consumer/PlayCounterCaching.cs @@ -55,7 +55,7 @@ namespace Selector.Cache await Task.WhenAll(tasks); - Logger.LogDebug($"Cached audio feature for [{track.DisplayString()}]"); + Logger.LogDebug($"Cached play count for [{track.DisplayString()}]"); } } } diff --git a/Selector.Cache/Extensions/ServiceExtensions.cs b/Selector.Cache/Extensions/ServiceExtensions.cs index 1c3a245..e066286 100644 --- a/Selector.Cache/Extensions/ServiceExtensions.cs +++ b/Selector.Cache/Extensions/ServiceExtensions.cs @@ -28,10 +28,19 @@ namespace Selector.Cache.Extensions public static void AddCachingConsumerFactories(this IServiceCollection services) { services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); + } + + public static void AddCachingSpotify(this IServiceCollection services) + { + services.AddSingleton(); } } } diff --git a/Selector.Web/Extensions/ServiceExtensions.cs b/Selector.Web/Extensions/ServiceExtensions.cs new file mode 100644 index 0000000..3d6d308 --- /dev/null +++ b/Selector.Web/Extensions/ServiceExtensions.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.DependencyInjection; +using Selector.Web.Service; + +namespace Selector.Web.Extensions +{ + public static class ServiceExtensions + { + public static void AddCacheHubProxy(this IServiceCollection services) + { + services.AddSingleton(); + services.AddHostedService(); + + services.AddTransient(); + services.AddScoped(); + } + } +} diff --git a/Selector.Web/Startup.cs b/Selector.Web/Startup.cs index 11cce1d..b9b055f 100644 --- a/Selector.Web/Startup.cs +++ b/Selector.Web/Startup.cs @@ -4,17 +4,16 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Authorization; using Microsoft.EntityFrameworkCore; -using Selector.Web.Service; using Selector.Web.Hubs; +using Selector.Web.Extensions; +using Selector.Extensions; using Selector.Model; using Selector.Model.Extensions; using Selector.Cache; @@ -97,14 +96,10 @@ namespace Selector.Web if (config.RedisOptions.Enabled) services.AddRedisServices(config.RedisOptions.ConnectionString); - services.AddSingleton(); - services.AddSingleton(); + services.AddSpotify(); + services.AddCachingSpotify(); - services.AddSingleton(); - services.AddHostedService(); - - services.AddTransient(); - services.AddScoped(); + services.AddCacheHubProxy(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/Selector/Extensions/ServiceExtensions.cs b/Selector/Extensions/ServiceExtensions.cs index 06ff65f..061a822 100644 --- a/Selector/Extensions/ServiceExtensions.cs +++ b/Selector/Extensions/ServiceExtensions.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Text; using Microsoft.Extensions.DependencyInjection; +using IF.Lastfm.Core.Api; + namespace Selector.Extensions { public static class ServiceExtensions @@ -10,7 +12,29 @@ namespace Selector.Extensions public static void AddConsumerFactories(this IServiceCollection services) { services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + + public static void AddSpotify(this IServiceCollection services) + { + services.AddSingleton(); + services.AddSingleton(); + } + + public static void AddLastFm(this IServiceCollection services, string client, string secret) + { + var lastAuth = new LastAuth(client, secret); + services.AddSingleton(lastAuth); + services.AddTransient(sp => new LastfmClient(sp.GetService())); + } + + public static void AddWatcher(this IServiceCollection services) + { + services.AddSingleton(); + services.AddSingleton(); } } }