Modern API Design with ASP.NET Core 2 by Fanie Reynders

Modern API Design with ASP.NET Core 2 by Fanie Reynders

Author:Fanie Reynders
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


When the Build function is executed, it will simply return an instance of itself, which is of type IConfigurationProvider. The provided ConfigurationProvider base class does most of the default plumbing for us; we just need to override its Load method :

public class AwesomeConfigurationProvider: ConfigurationProvider, IConfigurationSource

{

private readonly string fileName;

public AwesomeConfigurationProvider(string fileName)

{

this.fileName = fileName;

}

public override void Load()

{

using (var fs = new FileStream(fileName, FileMode.Open))

{

var doc = XDocument.Load(fs);

var connectionStrings = doc.Root.Descendants()

.Where(e => e.Name.Equals(XName.Get("connectionStrings")))

.Descendants(XName.Get("add")).Select(e =>

new KeyValuePair<string, string>($"connectionStrings:{e.Attribute(XName.Get("name")).Value}", e.Attribute(XName.Get("connectionString")).Value));

var appSettings = doc.Root.Descendants()

.Where(e => e.Name.Equals(XName.Get("appSettings")))

.Descendants(XName.Get("add")).Select(e =>

new KeyValuePair<string, string>($"appSettings:{e.Attribute(XName.Get("key")).Value}", e.Attribute(XName.Get("value")).Value));



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.