I have a custom configuration XML file came with an SDK. I like to use that file without modifying in order to avoid refactoring all the SDK files dependent on.
I tried with .addXMLFile
. But, apparently the XML file is not compatible with that.
And then I converted the XML file into json and tried with .addJsonFile
. But, it didn't work either, I mean there were several errors complaining about null objects. I don't want to ask on this part, maybe on another topic later on.
Therefore, I've decided to use the proven existing working file loading (StreamReader
) and mapping (Deserializing
) to my custom class(es).
So far so good. But, at this point, I am not sure how to proceed and append this custom configuration to the IConfiguration
in Startup
.
At least I tried that;
private readonly IConfiguration _configuration;
public void ConfigureServices(IServiceCollection services)
{
...
ICustomConfiguration settings = null;
settings = Settings.LoadFromFile("MyCustomConfig.xml"); // settings shows proper structure and data after loading here.
_configuration.Bind("CustomConfigurationFromFile", (CustomConfigurationFromFile)settings);
services.AddSingleton(settings);
...
}
Although this doesn't give any error or complain I couldn't see my custom configuration within the collections of the _configuration
. Either there is a silence error during binding or my understanding from bind
is not accurate.
Any input highly appreciated.