Getting all application defined configs as key/value in Aspnet Core












0















I am trying to get all the application defined configs (from appsettings.json in my case) in a key/value pair. The IConfiguration.AsEnumerable() does return all the configs but it has lot more that what is defined by the application. From this list, there is no way to get the context of where the config is coming from. I only want to get the configurations that application has defined.
Other option i tried was to iterate the CondigurationRoot.Providers and filter out the JsonConfigurationProvider but i see that 'Data' property is not exposed and there is no public API to get it either.



Any other API that i am missing and i should look into?










share|improve this question























  • Why don't you just build your own IConfiguration, using only appsettings.json? Something like new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true).Build();

    – Federico Dipuma
    Nov 14 '18 at 18:33













  • Also you can use you own class to map config on its properties - so there will be only settings that correspond to this class properties

    – Pavel Agarkov
    Nov 14 '18 at 18:35











  • @FedericoDipuma thanks that is one workaround i can look into. 'CreateDefaultBuilder' already loads both settings and secrets file for me and i wanted to leverage the same configuration to retrieve my configs that powers dashboard for me. While i can create another ConfigurationBuilder, it does seem like unnecessary overhead of loading the configs twice.

    – Sanjay Singh
    Nov 14 '18 at 18:41











  • @PavelAgarkov I don't have classes for all the configs. They are multi level json files we have access them just the string keys.

    – Sanjay Singh
    Nov 14 '18 at 18:43











  • Having class for each config is much more reliable and you also will be able to use IOption<T> to inject those configs directly into places where you need them

    – Pavel Agarkov
    Nov 15 '18 at 14:53
















0















I am trying to get all the application defined configs (from appsettings.json in my case) in a key/value pair. The IConfiguration.AsEnumerable() does return all the configs but it has lot more that what is defined by the application. From this list, there is no way to get the context of where the config is coming from. I only want to get the configurations that application has defined.
Other option i tried was to iterate the CondigurationRoot.Providers and filter out the JsonConfigurationProvider but i see that 'Data' property is not exposed and there is no public API to get it either.



Any other API that i am missing and i should look into?










share|improve this question























  • Why don't you just build your own IConfiguration, using only appsettings.json? Something like new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true).Build();

    – Federico Dipuma
    Nov 14 '18 at 18:33













  • Also you can use you own class to map config on its properties - so there will be only settings that correspond to this class properties

    – Pavel Agarkov
    Nov 14 '18 at 18:35











  • @FedericoDipuma thanks that is one workaround i can look into. 'CreateDefaultBuilder' already loads both settings and secrets file for me and i wanted to leverage the same configuration to retrieve my configs that powers dashboard for me. While i can create another ConfigurationBuilder, it does seem like unnecessary overhead of loading the configs twice.

    – Sanjay Singh
    Nov 14 '18 at 18:41











  • @PavelAgarkov I don't have classes for all the configs. They are multi level json files we have access them just the string keys.

    – Sanjay Singh
    Nov 14 '18 at 18:43











  • Having class for each config is much more reliable and you also will be able to use IOption<T> to inject those configs directly into places where you need them

    – Pavel Agarkov
    Nov 15 '18 at 14:53














0












0








0








I am trying to get all the application defined configs (from appsettings.json in my case) in a key/value pair. The IConfiguration.AsEnumerable() does return all the configs but it has lot more that what is defined by the application. From this list, there is no way to get the context of where the config is coming from. I only want to get the configurations that application has defined.
Other option i tried was to iterate the CondigurationRoot.Providers and filter out the JsonConfigurationProvider but i see that 'Data' property is not exposed and there is no public API to get it either.



Any other API that i am missing and i should look into?










share|improve this question














I am trying to get all the application defined configs (from appsettings.json in my case) in a key/value pair. The IConfiguration.AsEnumerable() does return all the configs but it has lot more that what is defined by the application. From this list, there is no way to get the context of where the config is coming from. I only want to get the configurations that application has defined.
Other option i tried was to iterate the CondigurationRoot.Providers and filter out the JsonConfigurationProvider but i see that 'Data' property is not exposed and there is no public API to get it either.



Any other API that i am missing and i should look into?







c# asp.net-core .net-core






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 18:26









Sanjay SinghSanjay Singh

514715




514715













  • Why don't you just build your own IConfiguration, using only appsettings.json? Something like new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true).Build();

    – Federico Dipuma
    Nov 14 '18 at 18:33













  • Also you can use you own class to map config on its properties - so there will be only settings that correspond to this class properties

    – Pavel Agarkov
    Nov 14 '18 at 18:35











  • @FedericoDipuma thanks that is one workaround i can look into. 'CreateDefaultBuilder' already loads both settings and secrets file for me and i wanted to leverage the same configuration to retrieve my configs that powers dashboard for me. While i can create another ConfigurationBuilder, it does seem like unnecessary overhead of loading the configs twice.

    – Sanjay Singh
    Nov 14 '18 at 18:41











  • @PavelAgarkov I don't have classes for all the configs. They are multi level json files we have access them just the string keys.

    – Sanjay Singh
    Nov 14 '18 at 18:43











  • Having class for each config is much more reliable and you also will be able to use IOption<T> to inject those configs directly into places where you need them

    – Pavel Agarkov
    Nov 15 '18 at 14:53



















  • Why don't you just build your own IConfiguration, using only appsettings.json? Something like new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true).Build();

    – Federico Dipuma
    Nov 14 '18 at 18:33













  • Also you can use you own class to map config on its properties - so there will be only settings that correspond to this class properties

    – Pavel Agarkov
    Nov 14 '18 at 18:35











  • @FedericoDipuma thanks that is one workaround i can look into. 'CreateDefaultBuilder' already loads both settings and secrets file for me and i wanted to leverage the same configuration to retrieve my configs that powers dashboard for me. While i can create another ConfigurationBuilder, it does seem like unnecessary overhead of loading the configs twice.

    – Sanjay Singh
    Nov 14 '18 at 18:41











  • @PavelAgarkov I don't have classes for all the configs. They are multi level json files we have access them just the string keys.

    – Sanjay Singh
    Nov 14 '18 at 18:43











  • Having class for each config is much more reliable and you also will be able to use IOption<T> to inject those configs directly into places where you need them

    – Pavel Agarkov
    Nov 15 '18 at 14:53

















Why don't you just build your own IConfiguration, using only appsettings.json? Something like new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true).Build();

– Federico Dipuma
Nov 14 '18 at 18:33







Why don't you just build your own IConfiguration, using only appsettings.json? Something like new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true).Build();

– Federico Dipuma
Nov 14 '18 at 18:33















Also you can use you own class to map config on its properties - so there will be only settings that correspond to this class properties

– Pavel Agarkov
Nov 14 '18 at 18:35





Also you can use you own class to map config on its properties - so there will be only settings that correspond to this class properties

– Pavel Agarkov
Nov 14 '18 at 18:35













@FedericoDipuma thanks that is one workaround i can look into. 'CreateDefaultBuilder' already loads both settings and secrets file for me and i wanted to leverage the same configuration to retrieve my configs that powers dashboard for me. While i can create another ConfigurationBuilder, it does seem like unnecessary overhead of loading the configs twice.

– Sanjay Singh
Nov 14 '18 at 18:41





@FedericoDipuma thanks that is one workaround i can look into. 'CreateDefaultBuilder' already loads both settings and secrets file for me and i wanted to leverage the same configuration to retrieve my configs that powers dashboard for me. While i can create another ConfigurationBuilder, it does seem like unnecessary overhead of loading the configs twice.

– Sanjay Singh
Nov 14 '18 at 18:41













@PavelAgarkov I don't have classes for all the configs. They are multi level json files we have access them just the string keys.

– Sanjay Singh
Nov 14 '18 at 18:43





@PavelAgarkov I don't have classes for all the configs. They are multi level json files we have access them just the string keys.

– Sanjay Singh
Nov 14 '18 at 18:43













Having class for each config is much more reliable and you also will be able to use IOption<T> to inject those configs directly into places where you need them

– Pavel Agarkov
Nov 15 '18 at 14:53





Having class for each config is much more reliable and you also will be able to use IOption<T> to inject those configs directly into places where you need them

– Pavel Agarkov
Nov 15 '18 at 14:53












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306602%2fgetting-all-application-defined-configs-as-key-value-in-aspnet-core%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306602%2fgetting-all-application-defined-configs-as-key-value-in-aspnet-core%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()