2023-04-30 20:25:40 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
using Azure.ResourceManager;
|
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using Proto.Cluster.AzureContainerApps.Stores.ResourceTags;
|
|
|
|
|
|
|
|
|
|
namespace Proto.Cluster.AzureContainerApps;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds extension methods to <see cref="IServiceCollection"/> for registering the Azure Container Apps provider
|
|
|
|
|
/// </summary>
|
|
|
|
|
[PublicAPI]
|
|
|
|
|
public static class ServiceCollectionExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds the Azure Container Apps provider to the service collection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="services">The service collection to add the provider to.</param>
|
|
|
|
|
/// <param name="armClientProvider">An <see cref="IArmClientProvider"/> to create <see cref="ArmClient"/> instances.</param>
|
2023-07-14 17:29:43 +00:00
|
|
|
/// <param name="configureMemberStore">An optional configuration for the member store.</param>
|
2023-04-30 20:25:40 +00:00
|
|
|
/// <param name="configure">An optional action to configure the provider options.</param>
|
|
|
|
|
/// <returns>The service collection.</returns>
|
2023-07-14 17:29:43 +00:00
|
|
|
public static IServiceCollection AddAzureContainerAppsProvider(this IServiceCollection services, IArmClientProvider? armClientProvider = default, Action<IServiceCollection>? configureMemberStore = null, Action<AzureContainerAppsProviderOptions>? configure = null)
|
2023-04-30 20:25:40 +00:00
|
|
|
{
|
|
|
|
|
var configureOptions = configure ?? (_ => { });
|
|
|
|
|
services.Configure(configureOptions);
|
|
|
|
|
services.ConfigureOptions<AzureContainerAppsProviderOptionsValidator>();
|
|
|
|
|
services.AddSingleton<AzureContainerAppsProvider>();
|
|
|
|
|
|
|
|
|
|
if (armClientProvider != null)
|
|
|
|
|
services.AddSingleton(armClientProvider);
|
|
|
|
|
|
2023-07-14 17:29:43 +00:00
|
|
|
if (configureMemberStore != null)
|
|
|
|
|
configureMemberStore.Invoke(services);
|
|
|
|
|
else
|
|
|
|
|
services.AddResourceTagsMemberStore();
|
2023-04-30 20:25:40 +00:00
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
}
|