Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

C# SDK samples should all use AddBotRuntime() in startup #3287

@johnataylor

Description

@johnataylor

The AddBotRuntime() extension function has been recently added to the SDK. This function registers with the Dependency Injection framework everything that is needed to run Adaptive Dialogs. This function builds the Composer runtime.

One of the important mechanisms at play here is that the various dependencies (the Adapter, Middleware, Storage, the Bot itself etc.) are added with the TryAddSingleton function, and this means they can be overridden.

While the default IBot that is registered actually runs Adaptive Dialogs it only takes a line of code in startup to override this with any other implementation. For example, an IBot implementation built in code derived from ActivityHandler. In other words there is nothing that limits this function to Adaptive Dialogs and Composer, it can be used to create the runtime for any IBot implementation.

Other than the obvious appeal of consistency and reuse, the advantage of using this approach is that the model shifts to one of overriding default working behavior with custom behavior. Previously the expectation was that the developer would have to know all the component parts and build up the runtime.

Although ultimately the developer who wishes to customize behavior will need to have an understanding of the various internal dependencies, what needs to be understood by the developer who just wants to get something working is significantly reduced.

This change also means there is an opportunity to consolidate aspects of the documentation as the way by which you customize and extend an Adaptive Dialog based Composer runtime is exactly the same way you customize and extend the runtime for a bot that was written all in code.

Specifically we should switch to using AddBotRuntime across all the SDK samples. For example:

services.AddSingleton<IBot, EchoBot>();
services.AddBotRuntime(Configuration);

and for a bot that uses Dialogs:

services.AddSingleton<MainDialog>();
services.AddSingleton<IBot, DialogBot<MainDialog>>();
services.AddBotRuntime(Configuration);

Metadata

Metadata

Assignees

Labels

P1Painful if we don't fix, won't block releasingfeature-requestA request for new functionality or an enhancement to an existing one.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions