Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to create a specific section in appsettings in appConfig

I have this list say product Type:

Type1
Type2 
Type3

and so on Now this list will keep increasing time to time and will be set via appsettings.

Now the key will not be really like Type1 orType2 these will be different. Like say

<add key="FoodItems" value="something"/>
<add key="Cosmetics" value="xyz"/>

so on.. So when I write the code i need to get the key and value from app config, I know how to get all keys but I want to put these under certain category so that I don't have to Parse the whole config file I will parse just this section and get all the types under it.

something like

<ItemList>
 <add key="FoodItems" value="something"/>
    <add key="Cosmetics" value="xyz"/>
</ItemList>

Is it possible to do something like that in appsettings? Or some other way but yes in appconfig specifically.

like image 402
Silver Avatar asked Apr 08 '14 02:04

Silver


People also ask

How do I create a custom section in app config?

Open the App. config file and add the configSections, sectionGroup and section to it. We need to specify the name and fully qualified type of all the section and section group.

What is AppSetting section in web config?

AppSetting section in the configuration file is a section that allows us to keep configurable and application wide settings (for e.g.: ConnectionString) that an application requires in order to perform the tasks properly. This helps in easy maintenance and deployment of the application.

Why appSettings keys in web config are not case sensitive?

Why appsettings keys (in web. config) are not case sensitive ? The default comparer is a CaseInsensitiveComparer that uses the conventions of the invariant culture; that is, key comparisons are case-insensitive by default.


1 Answers

What you want is your own custom Configuration Section. Here is a solid guide I've used before.

When using your own configuration section, you don't have to use a Dictionary type like appSettings does - you can define multiple properties, which sounds like what you are looking for.

An alternative is using sectiongroup element as indicated here.

like image 107
Jonesopolis Avatar answered Oct 08 '22 02:10

Jonesopolis