Sprog

ServiceCollectionExtensions.AddAgent Method

Definition

Overloads

Name Description
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>(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<TAdapter>(IServiceCollection, Func<IServiceProvider,IAgent>)

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

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddAgent<TAdapter>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Func<IServiceProvider,Microsoft.Agents.Builder.IAgent> implementationFactory) where TAdapter : Microsoft.Agents.Hosting.AspNetCore.CloudAdapter;
static member AddAgent : Microsoft.Extensions.DependencyInjection.IServiceCollection * Func<IServiceProvider, Microsoft.Agents.Builder.IAgent> -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Adapter :> Microsoft.Agents.Hosting.AspNetCore.CloudAdapter)
<Extension()>
Public Function AddAgent(Of TAdapter As CloudAdapter) (services As IServiceCollection, implementationFactory As Func(Of IServiceProvider, IAgent)) As IServiceCollection

Type Parameters

TAdapter

The type of the cloud adapter to associate with the agent. Must inherit from CloudAdapter.

Parameters

services
IServiceCollection

The service collection to which the agent and adapter are added.

implementationFactory
Func<IServiceProvider,IAgent>

A factory function that creates an instance of IAgent using the provided service provider.

Returns

Remarks

This method registers the specified agent and its adapter for dependency injection. The agent is registered with a transient lifetime. Call this method during application startup to enable agent-based functionality.

Applies to

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>();
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddAgent<TAgent,TAdapter>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) where TAgent : class, Microsoft.Agents.Builder.IAgent where TAdapter : Microsoft.Agents.Hosting.AspNetCore.CloudAdapter;
static member AddAgent : Microsoft.Extensions.DependencyInjection.IServiceCollection -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Agent : null and 'Agent :> Microsoft.Agents.Builder.IAgent and 'Adapter :> Microsoft.Agents.Hosting.AspNetCore.CloudAdapter)
<Extension()>
Public Function AddAgent(Of TAgent As {Class, IAgent}, TAdapter As {Class, IAgent}) (services As IServiceCollection) As IServiceCollection

Type Parameters

TAgent

The type of the agent to register. Must implement the IAgent interface.

TAdapter

The type of the cloud adapter to register. Must derive from CloudAdapter.

Parameters

services
IServiceCollection

The service collection to which the agent and adapter will be added.

Returns

Remarks

Registers both the agent and its adapter as transient services. Only one instance of each agent type is registered. AgentApplicationOptions is automatically registered if not already present. This method is typically used to configure multi-agent scenarios in applications that use dependency injection.

Applies to