ResourceExtensions.GetEnvironmentVariableValuesAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Get the environment variables from the given resource.
public static System.Threading.Tasks.ValueTask<System.Collections.Generic.Dictionary<string,string>> GetEnvironmentVariableValuesAsync (this Aspire.Hosting.ApplicationModel.IResourceWithEnvironment resource, Aspire.Hosting.DistributedApplicationOperation applicationOperation = Aspire.Hosting.DistributedApplicationOperation.Run);
static member GetEnvironmentVariableValuesAsync : Aspire.Hosting.ApplicationModel.IResourceWithEnvironment * Aspire.Hosting.DistributedApplicationOperation -> System.Threading.Tasks.ValueTask<System.Collections.Generic.Dictionary<string, string>>
<Extension()>
Public Function GetEnvironmentVariableValuesAsync (resource As IResourceWithEnvironment, Optional applicationOperation As DistributedApplicationOperation = Aspire.Hosting.DistributedApplicationOperation.Run) As ValueTask(Of Dictionary(Of String, String))
Parameters
- resource
- IResourceWithEnvironment
The resource to get the environment variables from.
- applicationOperation
- DistributedApplicationOperation
The context in which the AppHost is being executed.
Returns
The environment variables retrieved from the resource.
Examples
Using GetEnvironmentVariableValuesAsync(IResourceWithEnvironment, DistributedApplicationOperation) inside a unit test to validate environment variable values.
var builder = DistributedApplication.CreateBuilder();
var container = builder.AddContainer("elasticsearch", "library/elasticsearch", "8.14.0")
.WithEnvironment("discovery.type", "single-node")
.WithEnvironment("xpack.security.enabled", "true");
var env = await container.Resource.GetEnvironmentVariableValuesAsync();
Assert.Collection(env,
env =>
{
Assert.Equal("discovery.type", env.Key);
Assert.Equal("single-node", env.Value);
},
env =>
{
Assert.Equal("xpack.security.enabled", env.Key);
Assert.Equal("true", env.Value);
});
Remarks
This method is useful when you want to make sure the environment variables are added properly to resources, mostly in test situations. This method has asynchronous behavior when applicationOperation
is Run and environment variables were provided from IValueProvider otherwise it will be synchronous.