Skip to content

Commit c17d6a5

Browse files
authored
Update bot-builder-dotnet-state.md (MicrosoftDocs#545)
1 parent 8b2bcc7 commit c17d6a5

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

articles/dotnet/bot-builder-dotnet-state.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,38 @@ ms.date: 12/13/17
1818

1919
## In-memory data storage
2020

21-
In-memory data storage is intended for testing only. This storage is volatile and temporary. The data is cleared each time the bot is restarted. To use the in-memory storage for testing purposes, you will need to do two things. First, within the **Conversation.UpdateContainer** method, create a new instance of the in-memory storage:
21+
In-memory data storage is intended for testing only. This storage is volatile and temporary. The data is cleared each time the bot is restarted. To use the in-memory storage for testing purposes, you will need to:
2222

23-
```cs
24-
Conversation.UpdateContainer(
25-
builder =>
26-
{
27-
var store = new InMemoryDataStore();
28-
...
29-
});
30-
```
23+
Install the following NuGet packages:
24+
- Microsoft.Bot.Builder.Azure
25+
- Autofac.WebApi2
3126

32-
Then, register the new data store:
27+
In the **Application_Start** method, create a new instance of the in-memory storage, and register the new data store:
3328

3429
```cs
30+
// Global.asax file
31+
32+
var store = new InMemoryDataStore();
33+
3534
Conversation.UpdateContainer(
36-
builder =>
37-
{
38-
var store = new InMemoryDataStore();
39-
builder.Register(c => store)
40-
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
35+
builder =>
36+
{
37+
builder.Register(c => store)
38+
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
39+
.AsSelf()
40+
.SingleInstance();
41+
42+
builder.Register(c => new CachingBotDataStore(store,
43+
CachingBotDataStoreConsistencyPolicy
44+
.ETagBasedConsistency))
45+
.As<IBotDataStore<BotData>>()
4146
.AsSelf()
42-
.SingleInstance();
43-
});
47+
.InstancePerLifetimeScope();
48+
49+
50+
});
51+
GlobalConfiguration.Configure(WebApiConfig.Register);
52+
4453
```
4554

4655
You can use this method to set your own custom data storage or use any of the *Azure Extensions*.

0 commit comments

Comments
 (0)