Skip to content
Docs Try Aspire

AspireExportAttribute

Class sealed net8.0
📦 Aspire.Hosting v13.2.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. Specify just the method name - the capability ID is computed as {AssemblyName}/{methodName}. For example: "addRedis" in Aspire.Hosting.Redis becomes Aspire.Hosting.Redis/addRedis.
  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 - just specify the method name
[AspireExport("addRedis", Description = "Adds a Redis resource")]
public static IResourceBuilder<RedisResource> AddRedis(...) { }
// Scanner computes capability ID: Aspire.Hosting.Redis/addRedis
// 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