AspireExportAttribute
Class sealed net8.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
10 members
Remarks
Section titled RemarksThis attribute serves multiple purposes:
- 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 becomesAspire.Hosting.Redis/addRedis. - Type exports (on types): Marks a type as an ATS-exported type. The type ID is automatically derived as
{AssemblyName}/{TypeName}. For example:RedisResourcein Aspire.Hosting.Redis becomesAspire.Hosting.Redis/RedisResource. - Context types (on types with ExposeProperties): When
AspireExportAttribute.ExposePropertiesis true, the type's properties are automatically exposed as get/set capabilities for use in callbacks. - External type exports (assembly-level): For types you don't own, use assembly-level with
AspireExportAttribute.Typeproperty to include them in the ATS type system.
Constructors3
Section titled ConstructorsAspireExportAttribute(string) Initializes a new instance for a capability export (on methods).
AspireExportAttribute Initializes a new instance for a type export.
AspireExportAttribute(Type) Initializes a new instance for an assembly-level type export.
Properties7
Section titled PropertiesDescriptionget; setstring? Gets or sets a description of what this export does.
ExposeMethodsget; setbool Gets or sets whether to expose public instance methods of this type as ATS capabilities.
ExposePropertiesget; setbool Gets or sets whether to expose properties of this type as ATS capabilities.
Idgetstring? Gets the method name for capability exports.
MethodNameget; setstring? Gets or sets the method name to use in generated polyglot SDKs.
RunSyncOnBackgroundThreadget; setbool Gets or sets whether synchronous exported methods should be invoked on a background thread by the ATS dispatcher.
Typeget; setType? Gets or sets the CLR type for assembly-level type exports.
Examples
Section titled Examples// 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