ResourceExtensions.GetArgumentValuesAsync 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 arguments from the given resource.
public static System.Threading.Tasks.ValueTask<string[]> GetArgumentValuesAsync(this Aspire.Hosting.ApplicationModel.IResourceWithArgs resource, Aspire.Hosting.DistributedApplicationOperation applicationOperation = Aspire.Hosting.DistributedApplicationOperation.Run);
static member GetArgumentValuesAsync : Aspire.Hosting.ApplicationModel.IResourceWithArgs * Aspire.Hosting.DistributedApplicationOperation -> System.Threading.Tasks.ValueTask<string[]>
<Extension()>
Public Function GetArgumentValuesAsync (resource As IResourceWithArgs, Optional applicationOperation As DistributedApplicationOperation = Aspire.Hosting.DistributedApplicationOperation.Run) As ValueTask(Of String())
Parameters
- resource
- IResourceWithArgs
The resource to get the arguments from.
- applicationOperation
- DistributedApplicationOperation
The context in which the AppHost is being executed.
Returns
The arguments retrieved from the resource.
Examples
Using GetArgumentValuesAsync(IResourceWithArgs, DistributedApplicationOperation) inside a unit test to validate argument values.
var builder = DistributedApplication.CreateBuilder();
var container = builder.AddContainer("elasticsearch", "library/elasticsearch", "8.14.0")
.WithArgs("--discovery.type", "single-node")
.WithArgs("--xpack.security.enabled", "true");
var args = await container.Resource.GetArgumentsAsync();
Assert.Collection(args,
arg =>
{
Assert.Equal("--discovery.type", arg);
},
arg =>
{
Assert.Equal("--xpack.security.enabled", arg);
});
Remarks
This method is useful when you want to make sure the arguments are added properly to resources, mostly in test situations. This method has asynchronous behavior when applicationOperation
is Run and arguments were provided from IValueProvider otherwise it will be synchronous.