ConfigInjectorContributors / ConfigInjector

A simple way to inject strongly-typed configuration settings into your application via [web|app].config.
https://www.nuget.org/packages/ConfigInjector/
MIT License
61 stars 16 forks source link

Read values from XML files that aren't app.config or web.config #18

Open becdetat opened 9 years ago

becdetat commented 9 years ago

Windows 8/8.1 Store apps don't have app.configs or an equivalent. A common workaround is an embedded XML file that gets read using something similar to:

private static string LoadSetting(string settingKey)
{
    var assembly = typeof(AppConfig).GetTypeInfo().Assembly;

    using (var stream = assembly.GetManifestResourceStream("ABC.ConfigSettings.xml"))
    {
        var xmlDoc = XDocument.Load(stream);

        var appSettings = xmlDoc.Element("appSettings");

        var node = appSettings.Elements().Single(e => (string)e.Attribute("key") == settingKey);

        return (string)node.Attribute("value");
    }
}

It would be great if we could point ConfigInjector at an arbitrary embedded resource or string containing the properly formed XML.

daniellittledev commented 9 years ago

Or even an arbitrary list of key value pairs, for other settings sources