当前位置: 首页>>代码示例>>C#>>正文


C# IConfiguration.Get方法代码示例

本文整理汇总了C#中IConfiguration.Get方法的典型用法代码示例。如果您正苦于以下问题:C# IConfiguration.Get方法的具体用法?C# IConfiguration.Get怎么用?C# IConfiguration.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConfiguration的用法示例。


在下文中一共展示了IConfiguration.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateSecretReader

        public ISecretReader CreateSecretReader(IConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var vaultName = configuration.Get(VaultNameKey);
            ISecretReader secretReader;

            // Is key vault configured?
            if (string.IsNullOrEmpty(vaultName))
            {
                secretReader = new EmptySecretReader();
            }
            else
            {
                var clientId = configuration.Get(ClientIdKey);
                var certificateThumbprint = configuration.Get(CertificateThumbprintKey);

                // KeyVault is configured, but not all data is provided. Fail.
                if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(certificateThumbprint))
                {
                    throw new ArgumentException("Not all KeyVault configuration provided. " +
                                                $"Parameter: {VaultNameKey} Value: {VaultNameKey}, " +
                                                $"Parameter: {ClientIdKey} Value: {ClientIdKey}, " +
                                                $"Parameter: {CertificateThumbprintKey} Value: {certificateThumbprint}");
                }
               
                secretReader = new KeyVaultReader(new KeyVaultConfiguration(vaultName, clientId, certificateThumbprint, validateCertificate: true));
            }

            return secretReader;
        }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:34,代码来源:SecretReaderFactory.cs

示例2: Main

 public void Main(string[] args)
 {
     // Setup configuration sources.
     // The order in which Configuration is built
     // is important
     var builder = new ConfigurationBuilder(Options.ApplicationBaseDirectory)
         .AddJsonFile("config.json")
         .AddEnvironmentVariables()
         .AddUserSecrets()
         .AddCommandLine(args);
     Configuration = builder.Build();
     // Instantiate a new Twilio Rest Client
     var client = new TwilioRestClient(
       Configuration.Get("AccountSid"),
       Configuration.Get("AuthToken")
     );
     // Select all calls from my account
     var calls = client.ListCalls(new CallListRequest());
     // Check for any exceptions
     if (calls.RestException != null)
     {
         throw new FormatException(calls.RestException.Message);
     }
     // Loop through them and show information
     foreach (var call in calls.Calls)
     {
         var callDetails = $"From: {call.From}, Day: {call.DateCreated}, Duration: {call.Duration}s";
         WriteLine(callDetails);
     }
     ReadLine();
 }
开发者ID:ZhangYueqiu,项目名称:asp5-mvc6-examples,代码行数:31,代码来源:Program.cs

示例3: SearchResultsProvider

 public SearchResultsProvider(IConfiguration config)
 {
     _client = new HttpClient()
     {
         BaseAddress = new Uri(config.Get("GitHub:ApiBase") ?? DefaultApiBase)
     };
     var baseQuery = config.Get("GitHub:BaseQuery");
     _searchBaseUrl = $"/search/issues?per_page=100&sort=created&q=is:issue is:open label:\"needs design\" {baseQuery}";
     _authToken = config.Get("GitHub:AuthToken");
 }
开发者ID:glennc,项目名称:DesignBoard,代码行数:10,代码来源:SearchResultsProvider.cs

示例4: AzureADLoginProviderCredentials

        public AzureADLoginProviderCredentials(IConfiguration config)
        {
            ClientId = config.Get("ClientId");
            Authority = config.Get("Authority");
            RedirectUri = config.Get("RedirectUri");
            Caption = config.Get("Caption");

            Use = !string.IsNullOrWhiteSpace(ClientId)
                && !string.IsNullOrWhiteSpace(Authority)
                && !string.IsNullOrWhiteSpace(RedirectUri);
        }
开发者ID:XpiritBV,项目名称:PartsUnlimited,代码行数:11,代码来源:AzureADLoginProviderCredentials.cs

示例5: HueHelper

        public HueHelper(IConfiguration config)
        {
            _hueUserHash = config.Get("Hue:User");
              _lightName = config.Get("Hue:Light");
              _hueRed = int.Parse(config.Get("Hue:Colours:Red"));
              _hueGreen = int.Parse(config.Get("Hue:Colours:Green"));
              _hueYellow = int.Parse(config.Get("Hue:Colours:Yellow"));

              var bridgeInfos = HueProxy.DiscoverLocalBridges();
              var firstBridgeInfo = bridgeInfos[0];
              var hueContext = new HueContext(firstBridgeInfo, _hueUserHash);
              Proxy = new HueProxy(hueContext);
        }
开发者ID:korich,项目名称:BuildWatch,代码行数:13,代码来源:HueHelper.cs

示例6: AddCustomBindings

 public static void AddCustomBindings(this IServiceCollection services, IConfiguration configuration)
 {
     IMongoClient client = new MongoClient(configuration.Get("ConnectionString"));
     services.AddInstance<IMongoClient>(client);
     services.AddInstance<IMongoDatabase>(client.GetDatabase("VnextDB"));
     services.AddScoped<ITimesheetService, TimesheetService>();
 }
开发者ID:RobinVercammen,项目名称:VNextTest,代码行数:7,代码来源:Bindings.cs

示例7: Main

    public static void Main(string[] args = null)
    {
        ConfigurationBuilder configurationBuilder = 
                new ConfigurationBuilder();
            

        if (args == null)
        {
            // Add defaultConfigurationStrings
            configurationBuilder.AddInMemoryCollection(
                DefaultConfigurationStrings);
        }
        else
        {
            configurationBuilder
                .AddInMemoryCollection(DefaultConfigurationStrings)
                .AddJsonFile("Config.json", 
                    true) // bool indicates file is optional
                // "EssentialDotNetConfiguration" is an optional prefix for all 
                // environment configuration keys  
                .AddEnvironmentVariables("EssentialDotNetConfiguration")
                .AddCommandLine(
                    args, GetSwitchMappings(DefaultConfigurationStrings));
        }
        Configuration = configurationBuilder.Build();

        Console.WriteLine($"Hello {Configuration["Profile:UserName"]}");

        ConsoleWindow consoleWindow = 
                Configuration.Get<ConsoleWindow>("AppConfiguration:MainWindow");
        ConsoleWindow.SetConsoleWindow(consoleWindow);
    }
开发者ID:IntelliTect,项目名称:Articles,代码行数:32,代码来源:Program.cs

示例8: WebJobController

 public WebJobController(IConfiguration config)
 {
     //TODO Refactor
     IDictionary<string, string> settings = new Dictionary<string, string>();
     var storageCstr = config.Get("Provisioning:StorageConnectionString");
     settings.Add("Provisioning:StorageConnectionString", storageCstr);
     _settings = settings;   
 }
开发者ID:hpatel98,项目名称:SCAMP,代码行数:8,代码来源:WebJobController.cs

示例9: DumpConfig

 private static async Task DumpConfig(HttpResponse response, IConfiguration config, string indentation = "")
 {
     foreach (var child in config.GetSubKeys())
     {
         await response.WriteAsync(indentation + "[" + child.Key + "] " + config.Get(child.Key) + "\r\n");
         await DumpConfig(response, child.Value, indentation + "  ");
     }
 }
开发者ID:kulmugdha,项目名称:Entropy,代码行数:8,代码来源:Startup.cs

示例10: Startup

        public Startup(IApplicationEnvironment appEnv)
        {
            var configBuilder = new Microsoft.Framework.Configuration.ConfigurationBuilder(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json");
            Configuration = configBuilder.Build();
            connectionString = Configuration.Get("Data:DefaultConnection:ConnectionString");

        }
开发者ID:nitinV-Click2Cloud,项目名称:aspnet-connectionstrread,代码行数:8,代码来源:Startup.cs

示例11: SearchRepository

        public SearchRepository(IConfiguration configuration)
        {           
            var node = new Uri(configuration.Get("Development:ElasticsearchConnectionString"));

            var settings = new ConnectionSettings( node,  defaultIndex: "coolsearchengine");
            settings.MapDefaultTypeIndices(d => d.Add(typeof(AlarmMessage), INDEX_ALARMMESSAGE));
            settings.MapDefaultTypeNames(d => d.Add(typeof(AlarmMessage), TYPE_ALARMMESSAGE));

            client = new ElasticClient(settings);
        }
开发者ID:dVakulen,项目名称:AspNet5Watcher,代码行数:10,代码来源:SearchRepository.cs

示例12: ConfigurationWebsiteOptions

 public ConfigurationWebsiteOptions(IConfiguration config, ITelemetryProvider log)
 {
     try
     {
         ShowRecommendations = config.Get<bool>("ShowRecommendations");
     }
     catch (InvalidCastException e)
     {
         log.TrackException(e);
     }
 }
开发者ID:hjgraca,项目名称:PartsUnlimited,代码行数:11,代码来源:ConfigurationWebsiteOptions.cs

示例13: CassandraConnectionStringProvider

        public CassandraConnectionStringProvider(IConfiguration configuration)
        {
            var connection = configuration.Get<string>("Data:Cassandra", null);

            if (connection == null) return;

            if (string.IsNullOrEmpty(connection))
                return;

            _connectionString = connection;
        }
开发者ID:skimur,项目名称:skimur,代码行数:11,代码来源:CassandraConnectionStringProvider.cs

示例14: Startup

        public Startup(IApplicationEnvironment env, ILoggerFactory loggerFactory)
        {
            _configuration = new ConfigurationBuilder()
                                .AddJsonFile(env.ApplicationBasePath)
                                .AddEnvironmentVariables()
                                .Build();
            var loglevel = _configuration.Get("DefaultLogLevel");
            loggerFactory.AddConsole((LogLevel)Enum.Parse(typeof(LogLevel), loglevel));
            _logger = loggerFactory.CreateLogger<Startup>();

            _logger.LogInformation("fex server startin...");
        }
开发者ID:aggieben,项目名称:fex,代码行数:12,代码来源:Startup.cs

示例15: ConfigurationElasticClientSettings

        public ConfigurationElasticClientSettings(IConfiguration configuration)
        {
            ConnectionString = (configuration.Get<string>("ELASTICSEARCH_PORT")).Replace("tcp", "http");
            Uri uri = new Uri(ConnectionString);

            var elasticConfig = configuration.GetSection("ElasticSearch");
            int count;
            int.TryParse(elasticConfig.Get<string>("DefaultItemCount"), out count);
            DefaultItemCount = count;

            ConnectionSettings cs = new ConnectionSettings(uri, elasticConfig.Get<string>("DefaultIndex"));
            Client = new ElasticClient(cs);
        }
开发者ID:flakio,项目名称:catalog,代码行数:13,代码来源:ConfigurationElasticClientSettings.cs


注:本文中的IConfiguration.Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。