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;
///
/// Adds extension methods to for registering the Azure Container Apps provider
///
[PublicAPI]
public static class ServiceCollectionExtensions
{
///
/// Adds the Azure Container Apps provider to the service collection.
///
/// The service collection to add the provider to.
/// An to create instances.
/// An optional action to configure the provider options.
/// The service collection.
public static IServiceCollection AddAzureContainerAppsProvider(this IServiceCollection services, IArmClientProvider? armClientProvider = default, [AllowNull] Action configure = null)
{
var configureOptions = configure ?? (_ => { });
services.Configure(configureOptions);
services.ConfigureOptions();
services.AddSingleton();
if (armClientProvider != null)
services.AddSingleton(armClientProvider);
// Register the default member store.
services.AddSingleton(sp =>
{
var clientProvider = sp.GetRequiredService();
var logger = sp.GetRequiredService>();
var options = sp.GetRequiredService>().Value;
return new ResourceTagsClusterMemberStore(clientProvider, logger, options.ResourceGroupName, options.SubscriptionId);
});
return services;
}
}