Beispiel #1
0
        public static void ConfigureImageSearchClient(IServiceCollection services, IConfiguration config)
        {
            ImageSearchClientSettings settings =
                config.GetSection(ImageSearchClientSettings).Get <ImageSearchClientSettings>();

            services.AddSingleton <ImageSearchClientSettings>(settings);
        }
Beispiel #2
0
        public static IServiceCollection AddImageSearchClient(this IServiceCollection services, IConfiguration config)
        {
            ConfigureImageSearchClient(services, config);
            services.AddTransient <IImageSearchClient>(serviceProvider =>
            {
                ImageSearchClientSettings settings = serviceProvider.GetRequiredService <ImageSearchClientSettings>();

                ImageSearchClient searchClient = new ImageSearchClient(
                    new Microsoft.Azure.CognitiveServices.Search.ImageSearch.ApiKeyServiceClientCredentials(settings.SubscriptionKey),
                    System.Array.Empty <System.Net.Http.DelegatingHandler>())
                {
                    Endpoint = settings.Endpoint
                };

                return(searchClient);
            });

            return(services);
        }