// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Squidex.Domain.Apps.Entities.Contents.Text; using Squidex.Hosting; using Squidex.Hosting.Configuration; using Squidex.Infrastructure.Plugins; namespace Squidex.Extensions.Text.Azure { public sealed class AzureTextPlugin : IPlugin { public void ConfigureServices(IServiceCollection services, IConfiguration config) { var fullTextType = config.GetValue("fullText:type"); if (string.Equals(fullTextType, "Azure", StringComparison.OrdinalIgnoreCase)) { var serviceEndpoint = config.GetValue("fullText:azure:serviceEndpoint"); if (string.IsNullOrWhiteSpace(serviceEndpoint)) { var error = new ConfigurationError("Value is required.", "fullText:azure:serviceEndpoint"); throw new ConfigurationException(error); } var serviceApiKey = config.GetValue("fullText:azure:apiKey"); if (string.IsNullOrWhiteSpace(serviceApiKey)) { var error = new ConfigurationError("Value is required.", "fullText:azure:apiKey"); throw new ConfigurationException(error); } var indexName = config.GetValue("fullText:azure:indexName"); if (string.IsNullOrWhiteSpace(indexName)) { indexName = "squidex-index"; } services.AddSingleton( c => new AzureTextIndex(serviceEndpoint, serviceApiKey, indexName)); services.AddSingleton( c => c.GetRequiredService()); services.AddSingleton( c => c.GetRequiredService()); } } } }