|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Extensions.Logging;
namespace Aspire.Hosting.ApplicationModel;
/// <summary>
/// Gathers environment variables for resources.
/// </summary>
internal class EnvironmentVariablesExecutionConfigurationGatherer : IResourceExecutionConfigurationGatherer
{
/// <inheritdoc/>
public async ValueTask GatherAsync(IResourceExecutionConfigurationGathererContext context, IResource resource, ILogger resourceLogger, DistributedApplicationExecutionContext executionContext, CancellationToken cancellationToken = default)
{
if (resource.TryGetEnvironmentVariables(out var callbacks))
{
var callbackContext = new EnvironmentCallbackContext(executionContext, resource, context.EnvironmentVariables, cancellationToken)
{
Logger = resourceLogger,
};
foreach (var callback in callbacks)
{
await callback.Callback(callbackContext).ConfigureAwait(false);
}
}
}
} |