本文整理汇总了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;
}
示例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();
}
示例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");
}
示例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);
}
示例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);
}
示例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>();
}
示例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);
}
示例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;
}
示例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 + " ");
}
}
示例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");
}
示例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);
}
示例12: ConfigurationWebsiteOptions
public ConfigurationWebsiteOptions(IConfiguration config, ITelemetryProvider log)
{
try
{
ShowRecommendations = config.Get<bool>("ShowRecommendations");
}
catch (InvalidCastException e)
{
log.TrackException(e);
}
}
示例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;
}
示例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...");
}
示例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);
}