public static void Register(IConfiguration configuration, IServiceCollection services)
        {
            var spotifyClientConfiguration = new SpotifyClientConfiguration();

            configuration.GetSection("SpotifySettings").Bind(spotifyClientConfiguration);
            configuration.GetSection("SpotifyClientConfiguration").Bind(spotifyClientConfiguration);

            services.AddSingleton <IClientConfiguration>(spotifyClientConfiguration);

            var httpClient = new HttpClient()
            {
                Timeout = TimeSpan.FromSeconds(5)
            };

            services.AddSingleton(httpClient);

            var cacheConfiguration = new CacheConfiguration
            {
                Expiration = configuration.GetValue <int>("CacheExpirationMinutes")
            };

            services.AddSingleton(cacheConfiguration);
            services.AddSingleton <IMemoryCache, MemoryCache>();
            services.AddSingleton <IContentCache, ContentCache>();

            services.AddScoped <ISpotifyAuthClient, SpotifyAuthClient>();
            services.AddScoped <IClient, Client>();
            services.AddScoped <ISpotifyService, SpotifyService>();
        }
Beispiel #2
0
 public SpotifyClient(IOptions <SpotifyClientConfiguration> configuration, HttpClient httpClient, SpotifyRequestPagingCalculator pagingCalculator)
 {
     _configuration    = configuration.Value;
     _httpClient       = httpClient;
     _pagingCalculator = pagingCalculator;
     _httpClient.DefaultRequestHeaders.Accept.Add(
         new MediaTypeWithQualityHeaderValue("application/json"));
 }
Beispiel #3
0
 public SpotifyApiClient(SpotifyClientConfiguration clientConfig, IAuthenticationClient authClient, ILoggerFactory loggerFactory) : base(clientConfig, authClient)
 {
     _logger = loggerFactory.CreateLogger <SpotifyApiClient>();
 }
 public ApiClientBase(SpotifyClientConfiguration clientConfig, IAuthenticationClient authClient)
 {
     BaseUrl      = clientConfig.BaseUrl;
     ClientConfig = clientConfig;
     _authClient  = authClient;
 }