/// <summary>
        /// Adds bot runtime-related services to the application's service collection.
        /// </summary>
        /// <param name="services">The application's collection of registered services.</param>
        /// <param name="configuration">The application configuration.</param>
        public static void AddBotRuntime(this IServiceCollection services, IConfiguration configuration)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            // Component registrations must be added before the resource explorer is instantiated to ensure
            // that all types are correctly registered. Any types that are registered after the resource explorer
            // is instantiated will not be picked up otherwise.
            ComponentRegistrations.Add();

            // Configuration
            string applicationRoot = configuration.GetSection(ConfigurationConstants.ApplicationRootKey).Value;
            string defaultLocale   = configuration.GetSection(ConfigurationConstants.DefaultLocale).Value;
            string rootDialog      = configuration.GetSection(ConfigurationConstants.RootDialogKey).Value;

            // Runtime settings. If no config is provided, we create basic runtime config with defaults.
            var runtimeSettings = configuration.GetSection(ConfigurationConstants.RuntimeSettingsKey).Get <RuntimeSettings>() ?? new RuntimeSettings();

            // Bot
            services.AddSingleton <IBot, CoreBot>();
            services.AddOptions()
            .Configure <CoreBotOptions>(o =>
            {
                o.DefaultLocale = defaultLocale;
                o.RootDialog    = rootDialog;
            });

            // ResourceExplorer. TryAddSingleton will only add if there is no other registration for resource explorer.
            // Tests use this to inject custom resource explorers but could also be used for advanced runtime customization scenarios.
            services.TryAddSingleton <ResourceExplorer>(serviceProvider =>
                                                        new ResourceExplorer()
                                                        .AddFolder(applicationRoot)
                                                        .RegisterType <OnQnAMatch>(OnQnAMatch.Kind));

            // Runtime set up
            services.AddBotRuntimeSkills(runtimeSettings.Skills);
            services.AddBotRuntimeStorage(configuration, runtimeSettings);
            services.AddBotRuntimeTelemetry(runtimeSettings.Telemetry);
            services.AddBotRuntimeTranscriptLogging(configuration, runtimeSettings.Features);
            services.AddBotRuntimeFeatures(runtimeSettings.Features);
            services.AddBotRuntimePlugins(configuration, runtimeSettings);
            services.AddBotRuntimeAdapters(runtimeSettings);
        }
Example #2
0
 public ComponentRegistrationsFixture()
 {
     ComponentRegistrations.Add();
 }