diff --git a/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive.Testing/TestScript.cs b/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive.Testing/TestScript.cs index 503e563007..4c8cc9e424 100644 --- a/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive.Testing/TestScript.cs +++ b/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive.Testing/TestScript.cs @@ -202,10 +202,12 @@ await adapter.ProcessActivityAsync( DialogManager dm; if (callback == null) { - dm = new DialogManager(Dialog) + dm = new DialogManager() .UseResourceExplorer(resourceExplorer) .UseLanguageGeneration(); + dm.RootDialog = Dialog; + if (LanguagePolicy != null) { dm.UseLanguagePolicy(LanguagePolicy); diff --git a/libraries/Microsoft.Bot.Builder.Dialogs/DialogManager.cs b/libraries/Microsoft.Bot.Builder.Dialogs/DialogManager.cs index 8ef26913d8..e6bf159b9b 100644 --- a/libraries/Microsoft.Bot.Builder.Dialogs/DialogManager.cs +++ b/libraries/Microsoft.Bot.Builder.Dialogs/DialogManager.cs @@ -23,7 +23,6 @@ public class DialogManager private const string LastAccess = "_lastAccess"; private string _rootDialogId; private readonly string _dialogStateProperty; - private readonly object _lock = new object(); /// /// Initializes a new instance of the class. @@ -70,7 +69,34 @@ public DialogManager(Dialog rootDialog = null, string dialogStateProperty = null /// /// Root dialog to use to start conversation. /// - public Dialog RootDialog { get; set; } + public Dialog RootDialog + { + get + { + if (_rootDialogId != null) + { + return Dialogs.Find(_rootDialogId); + } + + return null; + } + + set + { + Dialogs = new DialogSet(); + if (value != null) + { + _rootDialogId = value.Id; + Dialogs.TelemetryClient = value.TelemetryClient; + Dialogs.Add(value); + RegisterContainerDialogs(RootDialog, registerRoot: false); + } + else + { + _rootDialogId = null; + } + } + } /// /// Gets or sets global dialogs that you want to have be callable. @@ -103,21 +129,6 @@ public DialogManager(Dialog rootDialog = null, string dialogStateProperty = null /// result of the running the logic against the activity. public async Task OnTurnAsync(ITurnContext context, CancellationToken cancellationToken = default) { - // Lazy initialize rootdialog so it can refer to assets like LG function templates - if (_rootDialogId == null) - { - lock (_lock) - { - if (_rootDialogId == null) - { - _rootDialogId = RootDialog.Id; - Dialogs.TelemetryClient = RootDialog.TelemetryClient; - Dialogs.Add(RootDialog); - RegisterContainerDialogs(RootDialog, registerRoot: false); - } - } - } - var botStateSet = new BotStateSet(); // Preload TurnState with DM TurnState.