ServiceCollectionExtensions Class

Definition

Provides extension methods for registering agent-related services, adapters, and middleware with dependency injection containers and application builders.

public static class ServiceCollectionExtensions
type ServiceCollectionExtensions = class
Public Module ServiceCollectionExtensions
Inheritance
ServiceCollectionExtensions

Remarks

These extension methods simplify the setup of agent applications by enabling the registration of agents, adapters, options, and supporting middleware. They are intended to be used during application startup to configure required services for agent-based architectures, such as those using CloudAdapter and AgentApplication. Methods in this class support both default and custom agent/adapters, and facilitate integration with ASP.NET Core's dependency injection and middleware pipelines.

Methods

Name Description
AddAgent(IHostApplicationBuilder, Func<IServiceProvider,IAgent>)

Adds an Agent via lambda construction.

builder.Services.AddSingleton<IStorage, MemoryStorage>();
builder.AddAgent(sp =>
{
   var options = new AgentApplicationOptions()
   {
      TurnStateFactory = () => new TurnState(sp.GetService<IStorage>());
   };

   var app = new AgentApplication(options);

   ...

   return app;
});
AddAgent<TAdapter>(IHostApplicationBuilder, Func<IServiceProvider,IAgent>)

This is the same as AddAgent(IHostApplicationBuilder, Func<IServiceProvider,IAgent>), except allows the use of any CloudAdapter subclass.

AddAgent<TAdapter>(IServiceCollection, Func<IServiceProvider,IAgent>)

Adds an agent and its associated adapter to the service collection using the specified implementation factory.

AddAgent<TAgent,TAdapter>(IHostApplicationBuilder)

Same as AddAgent<TAgent>(IHostApplicationBuilder) but allows for use of any CloudAdapter subclass.

builder.Services.AddSingleton<IStorage, MemoryStorage>();
builder.AddAgent<MyAgent, MyCustomAdapter>();
AddAgent<TAgent,TAdapter>(IServiceCollection)

Adds an agent and its associated cloud adapter to the service collection for dependency injection.

services.AddSingleton<IStorage, MemoryStorage>();
services.AddAgent<MyAgent, CloudAdapter>();
AddAgent<TAgent>(IHostApplicationBuilder)

Adds an Agent which subclasses AgentApplication

builder.Services.AddSingleton<IStorage, MemoryStorage>();
builder.AddAgent<MyAgent>();
AddAgentApplicationOptions(IHostApplicationBuilder, AutoSignInSelector)

Registers AgentApplicationOptions for AgentApplication-based Agents.

AddAgentApplicationOptions(IServiceCollection, AutoSignInSelector, Boolean)

Adds the required agent application options and, optionally, an auto sign-in selector to the service collection.

AddAgentCore(IHostApplicationBuilder)

Adds the core agent services.

  • IConnections, which uses IConfiguration for settings.
  • IChannelServiceClientFactory for ConnectorClient and UserTokenClient creations.
  • CloudAdapter, this is the default adapter that works with Azure Bot Service and Activity Protocol Agents.
AddAgentCore<TAdapter>(IHostApplicationBuilder)

Adds the core agent services using a derived CloudAdapter.

  • IConnections, which uses IConfiguration for settings.
  • IChannelServiceClientFactory for ConnectorClient and UserTokenClient creations.
  • CloudAdapter, this is the default adapter that works with Azure Bot Service and Activity Protocol Agents.
AddAgentCore<TAdapter>(IServiceCollection)

Adds core services required for Agent functionality, including the specified cloud adapter, to the application's dependency injection container.

AddAsyncAdapterSupport(IServiceCollection)

Adds background task and activity processing support to the specified service collection, enabling asynchronous task execution via hosted services and task queues.

AddCloudAdapter(IHostApplicationBuilder)

Add the default CloudAdapter.

AddCloudAdapter(IServiceCollection)

Add the default CloudAdapter.

AddCloudAdapter<T>(IHostApplicationBuilder)

Add a derived CloudAdapter.

AddCloudAdapter<T>(IServiceCollection)

Add a derived CloudAdapter.

UseHeaderPropagation(IApplicationBuilder)

Adds a middleware that collects headers to be propagated.

Applies to