|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.ExceptionServices;
using Microsoft.Extensions.Logging.Abstractions;
namespace Aspire.Hosting.Tests.Utils;
public static class EnvironmentVariableEvaluator
{
public static async ValueTask<Dictionary<string, string>> GetEnvironmentVariablesAsync(
IResource resource,
DistributedApplicationOperation applicationOperation = DistributedApplicationOperation.Run,
IServiceProvider? serviceProvider = null)
{
var executionContext = new DistributedApplicationExecutionContext(new DistributedApplicationExecutionContextOptions(applicationOperation)
{
ServiceProvider = serviceProvider
});
var executionConfiguration = await ExecutionConfigurationBuilder.Create(resource)
.WithEnvironmentVariablesConfig()
.BuildAsync(executionContext, NullLogger.Instance, CancellationToken.None);
if (executionConfiguration.Exception is not null)
{
ExceptionDispatchInfo.Throw(executionConfiguration.Exception);
}
return executionConfiguration.EnvironmentVariables.ToDictionary();
}
}
|