Reading AppSettings (edit)
public string NorthwindConnection { get { return this._configuration["ConnectionStrings:NorthwindDatabase"]; } } public string GetConnectionString(string connectionName) { return this._configuration.GetConnectionString(connectionName); }
ConfigManager
using Microsoft.Extensions.Configuration; namespace GeeksConfiguration { public class GeekConfigManager : IGeekConfigManager { private readonly IConfiguration _configuration; public GeekConfigManager(IConfiguration configuration) { this._configuration = configuration; } } }
NuGet
Install-Package Microsoft.Extensions.Configuration.Abstractions Install-Package Microsoft.Extensions.Configuration
Configuration
using Microsoft.Extensions.Configuration; namespace GeeksConfiguration { public interface IGeekConfigManager { string NorthwindConnection { get; } string EmailID { get; } string AccountKey { get; } string GetConnectionString(string connectionName); IConfigurationSection GetConfigurationSection(string Key); } }
AppSettings.json
{ "Logging": { "LogLevel": { "Default": "Warning" } }, "ConnectionStrings": { "NorthwindDatabase": "Data Source=(localdb)\\ProjectsV13;Initial Catalog=Northwind; Integrated Security=True;Connect Timeout=30;" }, "AppSeettings": { "EmailID": "geeks@array.com", "AccountKey" : "xlymrkar24arla" }, "AllowedHosts": "*" }
Class Library(.NET Standard) - Reading appsetting.json Configuration | TheCodeBuzz
Reading appsettings.json in .Net Core Class Library Using Dependency Injection : GeeksArray.com