コード例 #1
0
 public static ConfigurationServiceBuilder AddXml <TSettings>(this ConfigurationServiceBuilder builder,
                                                              string path,
                                                              Action <IServiceProvider, SettingsProviderOptions> configure)
     where TSettings : class, new()
 => AddProvider(builder, serviceProvider =>
 {
     var settingsProviderOptions = new SettingsProviderOptions();
     configure?.Invoke(serviceProvider, settingsProviderOptions);
     var provider = new XmlSettingsProvider <TSettings>(settingsProviderOptions, path);
     return(provider);
 });
コード例 #2
0
        public static ConfigurationServiceBuilder AddConfiguration(this IServiceCollection services)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var builder = new ConfigurationServiceBuilder(services);

            services.TryAddSingleton(typeof(IConfiguration <>), typeof(Configuration <>));
            services.TryAddSingleton(typeof(IConfigurator <>), typeof(Configurator <>));

            return(builder);
        }
コード例 #3
0
        public static ConfigurationServiceBuilder AddProvider <TSettings>(this ConfigurationServiceBuilder builder,
                                                                          Func <IServiceProvider, SettingsProvider <TSettings> > providerFactory)
            where TSettings : class, new()
        {
            if (providerFactory == null)
            {
                throw new ArgumentNullException(nameof(providerFactory));
            }

            builder.Services.TryAddSingleton(serviceProvider =>
            {
                var configurationOptions = new ConfigurationOptions <TSettings>(providerFactory(serviceProvider));

                return(configurationOptions);
            });

            return(builder);
        }
コード例 #4
0
 public static ConfigurationServiceBuilder AddProvider <TSettings>(this ConfigurationServiceBuilder builder,
                                                                   SettingsProvider <TSettings> provider)
     where TSettings : class, new()
 => AddProvider(builder, _ => provider);
コード例 #5
0
 public static ConfigurationServiceBuilder AddXml <TSettings>(this ConfigurationServiceBuilder builder,
                                                              string path,
                                                              Action <SettingsProviderOptions> configure = null)
     where TSettings : class, new()
 => AddXml <TSettings>(builder, path, (_, options) => configure?.Invoke(options));