ChannelAdapterAttribute Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Declares that an IChannelAdapter implementation handles inbound requests for a
specific channelId. Annotated adapters are auto-registered in the
IChannelAdapterRegistry so that shared-endpoint (Tier 2) dispatch and SDK features
(proactive messaging, diagnostics) can resolve the correct adapter by channelId.
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true, Inherited=false)]
public sealed class ChannelAdapterAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true, Inherited=false)>]
type ChannelAdapterAttribute = class
inherit Attribute
Public NotInheritable Class ChannelAdapterAttribute
Inherits Attribute
- Inheritance
-
ChannelAdapterAttribute
- Attributes
Remarks
This attribute operates like Microsoft.Agents.Core.Serialization.ActivityTypeAttribute: a source generator (ChannelAdapterInitSourceGenerator) emits an assembly-level ChannelAdapterInitAssemblyAttribute for every annotated adapter, and those assembly attributes are read off the loaded assemblies at runtime — so no explicit DI registration call (such as AddChannelAdapter) is required. Simply reference the assembly that declares the annotated adapter.
The annotated type must implement IChannelAdapter (so it can be resolved through IChannelAdapterRegistry) and should be public so consuming applications can preload its assembly; to also serve shared-endpoint HTTP dispatch it must implement the host's HTTP adapter contract (IAgentHttpAdapter in Microsoft.Agents.Hosting.AspNetCore). Both hold for adapters deriving from CloudAdapter or ChannelAdapter. It does not need to derive from CloudAdapter — the default Activity Protocol adapter (CloudAdapter) remains the registry default and is not annotated.
// Handles only Teams traffic routed through the shared /api/messages endpoint:
[ChannelAdapter("msteams")]
public class TeamsChannelAdapter : CloudAdapter { }
// A dedicated-protocol adapter that also participates in the registry:
[ChannelAdapter("a2a")]
public class A2AAdapter : ChannelAdapter, IAgentHttpAdapter { }
Constructors
| Name | Description |
|---|---|
| ChannelAdapterAttribute(String) |
Initializes a new instance of the ChannelAdapterAttribute class. |
Properties
| Name | Description |
|---|---|
| ChannelId |
The |