# AspireExportAttribute

- 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/AspireExportAttribute.cs)
- Inherits: `Attribute`

Marks a method, type, or assembly-level type as an ATS (Aspire Type System) export.

## Definition

```csharp
namespace Aspire.Hosting;

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

## Remarks

This attribute serves multiple purposes:

1. Capability exports (on methods): Marks a static method as an ATS capability. The capability ID is automatically derived as `{AssemblyName}/{camelCaseMethodName}`. For example: `AddRedis` in Aspire.Hosting.Redis becomes `Aspire.Hosting.Redis/addRedis`. Specify an explicit `id` only when disambiguation is needed (e.g., multiple overloads).
2. Type exports (on types): Marks a type as an ATS-exported type. The type ID is automatically derived as `{AssemblyName}/{TypeName}`. For example: `RedisResource` in Aspire.Hosting.Redis becomes `Aspire.Hosting.Redis/RedisResource`.
3. Context types (on types with ExposeProperties): When [AspireExportAttribute.ExposeProperties](/reference/api/csharp/aspire.hosting/aspireexportattribute/properties.md#exposeproperties) is true, the type's properties are automatically exposed as get/set capabilities for use in callbacks.
4. External type exports (assembly-level): For types you don't own, use assembly-level with [AspireExportAttribute.Type](/reference/api/csharp/aspire.hosting/aspireexportattribute/properties.md#type) property to include them in the ATS type system.

## Constructors

- [AspireExportAttribute(string)](/reference/api/csharp/aspire.hosting/aspireexportattribute/constructors.md#constructor-string) -- Initializes a new instance for a capability export (on methods) with an explicit capability ID.
- [AspireExportAttribute](/reference/api/csharp/aspire.hosting/aspireexportattribute/constructors.md#constructor) -- Initializes a new instance for a type or method export.
- [AspireExportAttribute(Type)](/reference/api/csharp/aspire.hosting/aspireexportattribute/constructors.md#constructor-type) -- Initializes a new instance for an assembly-level type export.

## Properties

- [Description](/reference/api/csharp/aspire.hosting/aspireexportattribute/properties.md#description) : `string?` `get; set` -- Gets or sets a description of what this export does.
- [ExposeMethods](/reference/api/csharp/aspire.hosting/aspireexportattribute/properties.md#exposemethods) : `bool` `get; set` -- Gets or sets whether to expose public instance methods of this type as ATS capabilities.
- [ExposeProperties](/reference/api/csharp/aspire.hosting/aspireexportattribute/properties.md#exposeproperties) : `bool` `get; set` -- Gets or sets whether to expose properties of this type as ATS capabilities.
- [Id](/reference/api/csharp/aspire.hosting/aspireexportattribute/properties.md#id) : `string?` `get` -- Gets the method name for capability exports.
- [MethodName](/reference/api/csharp/aspire.hosting/aspireexportattribute/properties.md#methodname) : `string?` `get; set` -- Gets or sets the method name to use in generated polyglot SDKs.
- [RunSyncOnBackgroundThread](/reference/api/csharp/aspire.hosting/aspireexportattribute/properties.md#runsynconbackgroundthread) : `bool` `get; set` -- Gets or sets whether synchronous exported methods should be invoked on a background thread by the ATS dispatcher.
- [Type](/reference/api/csharp/aspire.hosting/aspireexportattribute/properties.md#type) : `Type?` `get; set` -- Gets or sets the CLR type for assembly-level type exports.

## Examples

```csharp
// Capability export on a method - capability ID is auto-derived as Aspire.Hosting.Redis/addRedis
[AspireExport(Description = "Adds a Redis resource")]
public static IResourceBuilder<RedisResource> AddRedis(...) { }

// Capability export with explicit ID for disambiguation (e.g., multiple overloads)
[AspireExport("addRedisWithPort", Description = "Adds a Redis resource with a specific port")]
public static IResourceBuilder<RedisResource> AddRedis(..., int port) { }

// Type export - type ID derived as {AssemblyName}/{TypeName}
[AspireExport]
public class RedisResource : ContainerResource { }
// Type ID: Aspire.Hosting.Redis/RedisResource

// Context type with properties exposed as capabilities
[AspireExport(ExposeProperties = true)]
public class EnvironmentCallbackContext
{
    public Dictionary<string, object> EnvironmentVariables { get; }
    // Getter: Aspire.Hosting.ApplicationModel/EnvironmentCallbackContext.environmentVariables
    // Setter: Aspire.Hosting.ApplicationModel/EnvironmentCallbackContext.setEnvironmentVariables
}

// Member-level opt-in with ignore for specific members
[AspireExport(ExposeProperties = true)]
public class SomeContext
{
    public string Name { get; }  // Exposed
    [AspireExportIgnore]
    public ILogger Logger { get; }  // Not exposed
}

// Assembly-level export for types you don't own
[assembly: AspireExport(typeof(IConfiguration))]
// Type ID: Microsoft.Extensions.Configuration.Abstractions/IConfiguration
```
