Accessing a .NET Bot’s State via Dependency Injection


The .NET BotBuilder SDK has deprecated the StateClient class, leaving some to wonder how they should access their bot’s state. Premier Developer Consultant Ben Williams shares an example of using dependency injection in your BotFramework projects.


When using the .NET BotBuilder SDK’s dialog system, you can access the bot state using the dialog context. However, what if you don’t have the dialog context handy?

You have two options

  1. Pass the context around all the time

  2. Use the already built in IoC container to get the bot state.

With v3 of the Microsoft Bot Builder SDK, the documentation describes how to configure your bot to store its bot state data in either Azure Table storage or in a Cosmos DB. Notice that in the documentation, you configure the storage providers via Autofac registration (which Bot Builder uses internally to manage its various services). You should be able to get them back from the Autofac container via dependency injection.

You can read more of Ben’s post here.

Comments (0)

Skip to main content