Skip to content
Docs Try Aspire

AspireUnionAttribute

Class sealed net8.0
📦 Aspire.Hosting v13.2.0
Specifies that a parameter or property accepts a union of multiple ATS types.
namespace Aspire.Hosting;
public sealed class AspireUnionAttribute
: System.Attribute
{
// ...
}
Attribute

Use on method parameters to indicate the parameter accepts multiple types:

[AspireExport("withEnvironment")]
public static IResourceBuilder<T> WithEnvironment<T>(
this IResourceBuilder<T> builder,
string name,
[AspireUnion(typeof(string), typeof(ReferenceExpression))] object value)

Use on properties (especially Dictionary<string, object>) to specify the value type union:

[AspireExport(ExposeProperties = true)]
public class EnvironmentCallbackContext
{
[AspireUnion(
typeof(string),
typeof(ReferenceExpression),
typeof(EndpointReference))]
public Dictionary<string, object> EnvironmentVariables { get; }
}

Important: All types in the union must be valid ATS types (primitives, handles, DTOs, or collections thereof). The scanner will fail with an error if any type cannot be mapped to ATS.