You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.1 KiB
30 lines
1.1 KiB
using Microsoft.Extensions.Configuration;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Infrastructure.Extensions
|
|
{
|
|
public static class ConfigurationExtensions
|
|
{
|
|
public static Dictionary<string, string> GetConnectionStringValues(this IConfiguration configuration, string name)
|
|
{
|
|
return configuration.GetConnectionString(name).Split(';')
|
|
.ToDictionary(o => o.Split('=')[0], o => o.Split('=')[1]);
|
|
}
|
|
|
|
public static string GetAppSetting(this IConfiguration configuration, string name)
|
|
{
|
|
return configuration.GetSection("AppSettings").GetValue<string>(name);
|
|
}
|
|
public static T GetAppSetting<T>(this IConfiguration configuration, string name, T defaultValue)
|
|
{
|
|
return configuration.GetSection("AppSettings").GetValue(name, defaultValue);
|
|
}
|
|
|
|
public static Dictionary<string, string> GetAppSettings(this IConfiguration configuration, string name)
|
|
{
|
|
return configuration.GetAppSetting(name,"").Split(';')
|
|
.ToDictionary(o => o.Split('=')[0], o => o.Split('=')[1]);
|
|
}
|
|
}
|
|
} |