microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
teams.net/Libraries/Microsoft.Teams.Plugins/Microsoft.Teams.Plugins.AspNetCore.BotBuilder/Extensions
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 | |
| 4 | using Microsoft.AspNetCore.Mvc.ApplicationParts; |
| 5 | using Microsoft.Bot.Builder; |
| 6 | using Microsoft.Bot.Builder.Integration.AspNet.Core; |
| 7 | using Microsoft.Bot.Connector.Authentication; |
| 8 | using Microsoft.Extensions.DependencyInjection; |
| 9 | using Microsoft.Extensions.Hosting; |
| 10 | using Microsoft.Teams.Plugins.AspNetCore.Controllers; |
| 11 | |
| 12 | namespace Microsoft.Teams.Plugins.AspNetCore.Extensions; |
| 13 | |
| 14 | public 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 | } |