public SpotifyController(ILogger <SpotifyController> logger,
                          HttpClient httpClient,
                          SpotifyClient spotifyClient,
                          HelperMethods helperMethods,
                          ComputerVisionAPI computerVisionAPI,
                          CosmosAPI cosmosAPI,
                          SearchAPI searchAPI)
 {
     this.logger            = logger;
     this.httpClient        = httpClient;
     this.spotifyClient     = spotifyClient;
     this.helperMethods     = helperMethods;
     this.computerVisionAPI = computerVisionAPI;
     this.cosmosAPI         = cosmosAPI;
     this.searchAPI         = searchAPI;
 }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <SpotifyOptions>(Configuration.GetSection(SpotifyOptions.SectionName));
            services.Configure <ComputerVisionOptions>(Configuration.GetSection(ComputerVisionOptions.SectionName));
            services.Configure <CosmosOptions>(Configuration.GetSection(CosmosOptions.SectionName));
            services.Configure <SearchOptions>(Configuration.GetSection(SearchOptions.SectionName));

            services.AddScoped <SpotifyClient>(s =>
            {
                IOptions <SpotifyOptions> spotifyOptions = s.GetRequiredService <IOptions <SpotifyOptions> >();
                return(new SpotifyClient(spotifyOptions.Value.ClientId, spotifyOptions.Value.ClientSecret, spotifyOptions.Value.RedirectUrl));
            });
            services.AddSingleton <HttpClient>();
            services.AddSingleton <ComputerVisionAPI>(s =>
            {
                IOptions <ComputerVisionOptions> computerVisionOptions = s.GetRequiredService <IOptions <ComputerVisionOptions> >();
                HttpClient httpClient = s.GetRequiredService <HttpClient>();
                return(new ComputerVisionAPI(computerVisionOptions, httpClient));
            });
            services.AddSingleton <CosmosAPI>(s =>
            {
                IOptions <CosmosOptions> cosmosOptions = s.GetRequiredService <IOptions <CosmosOptions> >();
                CosmosAPI cosmosAPI = new CosmosAPI(cosmosOptions);
                // ensure CosmosAPI is setup before startup
                // Service setup can't be async so use this...
                cosmosAPI.Setup().GetAwaiter().GetResult();
                return(cosmosAPI);
            });
            services.AddSingleton <SearchAPI>(s =>
            {
                IOptions <SearchOptions> searchOptions = s.GetRequiredService <IOptions <SearchOptions> >();
                SearchAPI searchAPI = new SearchAPI(searchOptions);
                return(searchAPI);
            });
            services.AddSingleton <HelperMethods>();

            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "AlbumImageSearch", Version = "v1"
                });
            });
        }