コード例 #1
0
        /// <summary>
        /// Create a new <see cref="IConfiguration"/> using a <see cref="PlaceholderResolverProvider"/> which wraps the provided <see cref="IConfiguration"/>.
        /// The new configuration will then be used to replace the current <see cref="IConfiguration"/> in the service container. All subsequent requests for a
        /// <see cref="IConfiguration"/> will return the newly created one providing placeholder resolution.
        /// </summary>
        /// <param name="services">the current service container</param>
        /// <param name="configuration">the configuration the placeholder resolver will wrap</param>
        /// <param name="loggerFactory">the log factory to use</param>
        /// <returns>the new configuration</returns>
        public static IConfiguration ConfigurePlaceholderResolver(this IServiceCollection services, IConfiguration configuration, ILoggerFactory loggerFactory = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var newConfig = configuration.AddPlaceholderResolver(loggerFactory);

            services.Replace(ServiceDescriptor.Singleton(typeof(IConfiguration), newConfig));

            return(newConfig);
        }