/// <inheritdoc cref="AutoBindOptionsModuleLoaderBuilderExtensions.AutoBindModuleOptions(IModuleLoaderBuilder, Action{OptionsBindOptions}?)"/>
        public static IHostBuilder AutoBindModuleOptions(this IHostBuilder hostBuilder, Action <OptionsBindOptions>?optionAction = null)
        {
            var bindOptions = new OptionsBindOptions();

            optionAction?.Invoke(bindOptions);

            return(hostBuilder.InternalAddBootstrapInterceptor(new OptionsBindModulesBootstrapInterceptor(new DefaultOptionsBinder(bindOptions))));
        }
Example #2
0
        /// <summary>
        /// 自动绑定标记了<see cref="AutoRegisterServicesInAssemblyAttribute"/>的模块中继承了<see cref="IOptions{TOptions}"/>的类。
        /// <para/>
        /// 默认情况下使用其完整名称为路径,在<see cref="IConfiguration"/>查找节点,并绑定值。
        /// <para/>
        /// 如 A 类命名空间为 B.C.D.E.F ,则<see cref="IConfiguration"/>查找路径为 B:C:D:E:F:A
        /// <para/>
        /// Note: 构建过程中必须有可访问的<see cref="IConfiguration"/> !!!
        /// </summary>
        /// <param name="moduleLoaderBuilder"></param>
        /// <param name="optionAction">配置选项的委托</param>
        /// <returns></returns>
        public static IModuleLoaderBuilder AutoBindModuleOptions(this IModuleLoaderBuilder moduleLoaderBuilder, Action <OptionsBindOptions>?optionAction = null)
        {
            var options = new OptionsBindOptions();

            optionAction?.Invoke(options);

            moduleLoaderBuilder.ModuleLoadOptions.ModulesBootstrapInterceptors.Add(new OptionsBindModulesBootstrapInterceptor(new DefaultOptionsBinder(options)));

            return(moduleLoaderBuilder);
        }