# AspireUnionAttribute

- Kind: `class`
- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Version: `13.3.0`
- Namespace: `Aspire.Hosting`
- Target framework: `net8.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/Ats/AspireUnionAttribute.cs)
- Inherits: `Attribute`

Specifies that a parameter or property accepts a union of multiple ATS types.

## Definition

```csharp
namespace Aspire.Hosting;

public sealed class AspireUnionAttribute
    : System.Attribute
{
    // ...
}
```

## Remarks

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

```csharp
[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:

```csharp
[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.

## Constructors

- [AspireUnionAttribute(Type[])](/reference/api/csharp/aspire.hosting/aspireunionattribute/constructors.md#constructor-type) -- Initializes a new instance with the types that form the union.

## Properties

- [Types](/reference/api/csharp/aspire.hosting/aspireunionattribute/properties.md#types) : `Type[]` `get` -- Gets the CLR types that form the union.
