microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/close-pull-request

Branches

Tags

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

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.Plugins/Microsoft.Teams.Plugins.AspNetCore.BotBuilder/Extensions/HostApplicationBuilder.cs

51lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4using Microsoft.AspNetCore.Mvc.ApplicationParts;
5using Microsoft.Bot.Builder;
6using Microsoft.Bot.Builder.Integration.AspNet.Core;
7using Microsoft.Bot.Connector.Authentication;
8using Microsoft.Extensions.DependencyInjection;
9using Microsoft.Extensions.Hosting;
10using Microsoft.Teams.Plugins.AspNetCore.Controllers;
11
12namespace Microsoft.Teams.Plugins.AspNetCore.Extensions;
13
14public static class HostApplicationBuilderExtensions
15{
16 public static IHostApplicationBuilder AddBotBuilder(this IHostApplicationBuilder builder)
17 {
18 builder.Services.AddControllers().ConfigureApplicationPartManager((apm) =>
19 {
20 apm.FeatureProviders.Add(new RemoveDefaultMessageController());
21 apm.ApplicationParts.Add(new AssemblyPart(typeof(MessageController).Assembly));
22 });
23 return builder;
24 }
25
26 public static IHostApplicationBuilder AddBotBuilder<TBot>(this IHostApplicationBuilder builder, BotFrameworkAuthentication authentication, IBotFrameworkHttpAdapter adapter) where TBot : class, IBot
27 {
28 builder.Services.AddSingleton(authentication);
29 builder.Services.AddSingleton(adapter);
30 builder.Services.AddTransient<IBot, TBot>();
31 builder.Services.AddControllers().ConfigureApplicationPartManager((apm) =>
32 {
33 apm.FeatureProviders.Add(new RemoveDefaultMessageController());
34 apm.ApplicationParts.Add(new AssemblyPart(typeof(MessageController).Assembly));
35 });
36 return builder;
37 }
38
39 public static IHostApplicationBuilder AddBotBuilder<TBot, TBotFrameworkHttpAdapter, TBotFrameworkAuthentication>(this IHostApplicationBuilder builder) where TBot : class, IBot where TBotFrameworkAuthentication : BotFrameworkAuthentication where TBotFrameworkHttpAdapter : class, IBotFrameworkHttpAdapter
40 {
41 builder.Services.AddSingleton<BotFrameworkAuthentication, TBotFrameworkAuthentication>();
42 builder.Services.AddSingleton<IBotFrameworkHttpAdapter, TBotFrameworkHttpAdapter>();
43 builder.Services.AddTransient<IBot, TBot>();
44 builder.Services.AddControllers().ConfigureApplicationPartManager((apm) =>
45 {
46 apm.FeatureProviders.Add(new RemoveDefaultMessageController());
47 apm.ApplicationParts.Add(new AssemblyPart(typeof(MessageController).Assembly));
48 });
49 return builder;
50 }
51}