From 20d115924c2838710b62a0870b72172456b8cbf6 Mon Sep 17 00:00:00 2001 From: Bas Brekelmans Date: Wed, 2 Sep 2020 10:35:55 -0700 Subject: [PATCH] Allow resource explorer to accept the set of declarative type registrations --- .../Resources/ResourceExplorer.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/libraries/Microsoft.Bot.Builder.Dialogs.Declarative/Resources/ResourceExplorer.cs b/libraries/Microsoft.Bot.Builder.Dialogs.Declarative/Resources/ResourceExplorer.cs index b8deb565b..b08e51a0f 100644 --- a/libraries/Microsoft.Bot.Builder.Dialogs.Declarative/Resources/ResourceExplorer.cs +++ b/libraries/Microsoft.Bot.Builder.Dialogs.Declarative/Resources/ResourceExplorer.cs @@ -30,6 +30,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Declarative.Resources private readonly ConcurrentDictionary kindToType = new ConcurrentDictionary(); private readonly ConcurrentDictionary> typeToKinds = new ConcurrentDictionary>(); private List resourceProviders = new List(); + private List declarativeTypes; private CancellationTokenSource cancelReloadToken = new CancellationTokenSource(); private ConcurrentBag changedResources = new ConcurrentBag(); private bool typesLoaded = false; @@ -49,9 +50,19 @@ namespace Microsoft.Bot.Builder.Dialogs.Declarative.Resources /// /// The list of resource providers to initialize the current instance. public ResourceExplorer(IEnumerable providers) - : this() + : this(providers, null) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The list of resource providers to initialize the current instance. + /// A list of declarative types to use. Falls back to if set to null. + public ResourceExplorer(IEnumerable providers, IEnumerable declarativeTypes) { this.resourceProviders = providers.ToList(); + this.declarativeTypes = declarativeTypes?.ToList(); } /// @@ -495,6 +506,11 @@ namespace Microsoft.Bot.Builder.Dialogs.Declarative.Resources Changed?.Invoke(this, resources); } + private IEnumerable GetComponentRegistrations() + { + return this.declarativeTypes ?? ComponentRegistration.Components.OfType(); + } + private void RegisterTypeInternal(string kind, Type type, ICustomDeserializer loader = null) { // Default loader if none specified @@ -543,7 +559,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Declarative.Resources // this can be reentrant, and we only want to do once. this.typesLoaded = true; - foreach (var component in ComponentRegistration.Components.OfType()) + foreach (var component in GetComponentRegistrations()) { if (component != null) {