microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
3ddf9fa76ec1801a0e3ca312c6d9855879571ac1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

core/src/Microsoft.Teams.Apps.BotBuilder/CompatHostingExtensions.cs

49lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.Bot.Builder.Integration.AspNet.Core;
5using Microsoft.Extensions.DependencyInjection;
6using Microsoft.Extensions.Hosting;
7using Microsoft.Teams.Core.Hosting;
8
9namespace Microsoft.Teams.Apps.BotBuilder;
10
11/// <summary>
12/// Provides extension methods for registering compatibility adapters and related services to support legacy bot hosting
13/// scenarios.
14/// </summary>
15/// <remarks>These extension methods simplify the integration of compatibility adapters into modern hosting
16/// environments by adding required services to the dependency injection container. Use these methods to enable legacy
17/// bot functionality within applications built on the current hosting model.</remarks>
18public static class CompatHostingExtensions
19{
20 /// <summary>
21 /// Adds compatibility adapter services to the application's dependency injection container.
22 /// </summary>
23 /// <remarks>This method registers services required for compatibility scenarios. It can be called
24 /// multiple times without adverse effects.</remarks>
25 /// <param name="builder">The host application builder to which the compatibility adapter services will be added. Cannot be null.</param>
26 /// <returns>The same <paramref name="builder"/> instance, enabling method chaining.</returns>
27 public static IHostApplicationBuilder AddTeamsBotFrameworkHttpAdapter(this IHostApplicationBuilder builder)
28 {
29 ArgumentNullException.ThrowIfNull(builder);
30 builder.Services.AddTeamsBotFrameworkHttpAdapter();
31 return builder;
32 }
33
34 /// <summary>
35 /// Registers the compatibility bot adapter and related services required for Bot Framework HTTP integration with
36 /// the application's dependency injection container.
37 /// </summary>
38 /// <remarks>Call this method during application startup to enable Bot Framework HTTP endpoint support
39 /// using the compatibility adapter. This method should be invoked before building the service provider.</remarks>
40 /// <param name="services">The service collection to which the compatibility adapter and related services will be added. Must not be null.</param>
41 /// <returns>The same <see cref="IServiceCollection"/> instance provided in <paramref name="services"/>, with the
42 /// compatibility adapter and related services registered.</returns>
43 public static IServiceCollection AddTeamsBotFrameworkHttpAdapter(this IServiceCollection services)
44 {
45 services.AddBotApplication();
46 services.AddSingleton<IBotFrameworkHttpAdapter, TeamsBotFrameworkHttpAdapter>();
47 return services;
48 }
49}
50