Skip to content

Simplify dependency management for TeamsBotApplication#521

Merged
MehakBindra merged 13 commits into
mainfrom
mehak/teamsapp-dep
May 27, 2026
Merged

Simplify dependency management for TeamsBotApplication#521
MehakBindra merged 13 commits into
mainfrom
mehak/teamsapp-dep

Conversation

@MehakBindra
Copy link
Copy Markdown
Collaborator

@MehakBindra MehakBindra commented May 22, 2026

This pull request refactors the Teams bot application hosting model to simplify bot setup and handler registration, unify options management, and streamline dependency injection. Key changes include updating the TeamsBotApplication constructor and options pattern, consolidating handler registration into bot subclasses, and improving the ApiClient interface. The sample bots and tests are updated to reflect these changes.

TeamsBotApplication and Options Refactoring:

  • The TeamsBotApplication constructor now takes an ApiClient, IHttpContextAccessor, a logger, and an optional TeamsBotApplicationOptions, consolidating the previously separate conversation and user token clients into the ApiClient. The options class now inherits from BotApplicationOptions for unified configuration.

Sample Bot Simplification:

  • The ExtAIBot sample is refactored: handler registration is moved from a static extension method into the ExtAIBotApp class constructor, and the DI registration is updated to use the new hosting model.

ApiClient Interface Improvements:

  • ApiClient now exposes ConversationClient and UserTokenClient as internal properties instead of private fields, improving testability and consistency. All constructors and copy methods are updated accordingly.

Configuration and Dependency Injection Updates:

  • The Teams bot options now automatically set the AppId from the resolved bot configuration. The ExtAIBot sample's appsettings.json and DI registrations are updated to match the new options and Azure OpenAI configuration pattern.

Test and Code Cleanup:

  • Unit tests are updated to use the new constructor patterns, and unnecessary project references are removed.

Copilot AI review requested due to automatic review settings May 22, 2026 19:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a TeamsBotApplicationDependencies record to bundle constructor dependencies for TeamsBotApplication, updates hosting registration to provide that bundle via DI, and refactors samples/tests to use the new constructor pattern.

Changes:

  • Added TeamsBotApplicationDependencies record and updated TeamsBotApplication to be constructed from the bundled dependencies.
  • Updated AddTeamsBotApplication hosting extension to register the bundle and added unit tests validating DI resolution.
  • Refactored sample bots (ExtAIBot, CustomHosting) and updated unit tests to use the bundled constructor.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
core/test/Microsoft.Teams.Apps.UnitTests/TeamsBotApplicationTests.cs Updates tests to construct TeamsBotApplication via dependencies bundle.
core/test/Microsoft.Teams.Apps.UnitTests/TeamsBotApplicationHostingExtensionsTests.cs Adds new tests validating DI registration/resolution of the bundle and bundled ctor subclassing.
core/test/Microsoft.Teams.Apps.UnitTests/PromptPreviewTests.cs Updates harness construction to use the dependencies bundle.
core/test/Microsoft.Teams.Apps.UnitTests/OAuthFlowTests.cs Updates harness construction to use the dependencies bundle.
core/src/Microsoft.Teams.Apps/TeamsBotApplicationDependencies.cs Adds the new dependencies bundle record type.
core/src/Microsoft.Teams.Apps/TeamsBotApplication.HostingExtensions.cs Registers TeamsBotApplicationDependencies in DI during AddTeamsBotApplication.
core/src/Microsoft.Teams.Apps/TeamsBotApplication.cs Switches construction to the bundled-dependencies ctor.
core/samples/ExtAIBot/Program.cs Switches sample to register/use a TeamsBotApplication subclass and updates Azure OpenAI config key usage.
core/samples/ExtAIBot/ExtAIBotApp.cs Refactors handler wiring into a TeamsBotApplication subclass using bundled ctor + DI.
core/samples/ExtAIBot/appsettings.json Renames Azure OpenAI config key from ModelId to Deployment.
core/samples/CustomHosting/MyTeamsBotApp.cs Updates sample subclass to use bundled dependencies ctor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/src/Microsoft.Teams.Apps/TeamsBotApplication.cs Outdated
MehakBindra and others added 2 commits May 22, 2026 12:28
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 22, 2026 19:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings May 22, 2026 21:05
@MehakBindra MehakBindra requested a review from rido-min May 22, 2026 21:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

core/src/Microsoft.Teams.Apps/TeamsBotApplication.HostingExtensions.cs:114

  • TeamsBotApplicationOptions is intended to be "a single options object" for both Core and Teams settings, but AddTeamsBotApplication currently registers both TeamsBotApplicationOptions and a separate BotApplicationOptions via AddBotApplication. This means DI consumers resolving BotApplicationOptions will not see the Teams options instance (and could diverge if configure changes inherited properties like AppId or ProcessActivityTimeout). Consider registering BotApplicationOptions to resolve to the same singleton instance as TeamsBotApplicationOptions (override the AddBotApplication registration).
        // Register TeamsBotApplicationOptions
        TeamsBotApplicationOptions teamsOptions = new() { AppId = botConfig.ClientId };
        configure?.Invoke(teamsOptions);
        services.AddSingleton(teamsOptions);

        services.AddBotApplication<TApp>(botConfig);

Comment thread core/src/Microsoft.Teams.Apps/TeamsBotApplication.cs
Comment thread core/samples/ExtAIBot/ExtAIBotApp.cs Outdated
Copilot AI review requested due to automatic review settings May 27, 2026 23:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

core/samples/ExtAIBot/ExtAIBotApp.cs:30

  • ExtAIBotApp requests ILogger<ExtAIBotApp> and forwards it to TeamsBotApplication, but TeamsBotApplication currently expects ILogger<TeamsBotApplication> (and forwards to BotApplication). This is a compile-time mismatch; align the logger parameter types (either make the base accept non-generic ILogger or request the expected ILogger<...> here).

Comment thread core/src/Microsoft.Teams.Apps/TeamsBotApplication.cs
Comment thread core/src/Microsoft.Teams.Apps/TeamsBotApplication.cs
Comment thread core/samples/CustomHosting/MyTeamsBotApp.cs
@MehakBindra MehakBindra added this pull request to the merge queue May 27, 2026
Merged via the queue into main with commit fc3aaaa May 27, 2026
12 checks passed
@MehakBindra MehakBindra deleted the mehak/teamsapp-dep branch May 27, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants