Skip to content
Docs Try Aspire
Docs Try

AspireExportAttribute

Class sealed net8.0
📦 Aspire.Hosting v13.3.0
Marks a method, type, or assembly-level type as an ATS (Aspire Type System) export.
namespace Aspire.Hosting;
public sealed class AspireExportAttribute
: System.Attribute
{
// ...
}
Attribute

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 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 property to include them in the ATS type system.
// 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