configuration of application, how to store it?
- mcmatak
- Member | 504
again and again i am developing this thing, where and how you store 1000 and more configuration directives?
bcs of lot of items in this configuration, is good to store it in some hierarchy, the best is tree, so the database is the worse for me and the next reason is that any directive is another type, you need to store
boolean, int, string, array
so store it in rows of database table is not suitable for me, also the columns of database table, bcs of hierarchy, is not the best
in past i tried xml, json, etc. serialized and stored as text in cell of database table
but you need to work with this configuration
1. access to values like
->getConfig(‘import.pohoda.invoices.book’)
2. set values like
->setConfig(‘import.pohoda.invoices.book’, “ESHOP”)
maybe the neon configuration could be fine, but what about the array?
‘company.bankAccounts[0].number’ = 123456798132
what you use? what is the best practice?
thanks for opinions
- Oli
- Member | 1215
You can choose: https://en.wikipedia.org/…lue_database. But very common are redis, memcached, … Both are supported by Nette. Redis through Kdyby/Redis.
- paulnevinthomas
- Member | 1
Start Visual Studio .NET or Visual Studio 2005.
On the File menu, point to New, and then click Project.
Click Visual C# under Project Types, and then click Console Application under
Templates. Name the project ConConfig. By default, Visual C# creates a class that is named Program.
Note In Visual Studio .NET 2003, click Visual C# Projects under Project
Types, and then click Console Application under Templates. Name the project
ConConfig. By default, Visual C# creates a class that is named Class1.
Make sure that the Solution Explorer window is visible. If it is not visible,
press the CTRL+ALT+L key combination.
In Solution Explorer, right-click the project name, click Add, and then click
New Item.
In the Add New Item list, click to select XML File.
In the Name text box, type App.config, and then click Add.
Note In Visual Studio .NET 2003, click Open.
You can use an application configuration file to collect custom application
settings that you save in key/value format. You can include <add> elements
in the <appSettings> section of an associated configuration file. Each
key/value pair has one <add> element. An <add> element has the
following format:
<add key=“Key0” value=“0” />
Add an <appSettings> section with <add> elements to the
configuration file between the <configuration> and
</configuration> tags.
For example, the following configuration file includes an <appSettings>
section that specifies three key/value pairs:
<?xml version=“1.0” encoding=“utf-8” ?>
<configuration>
<appSettings>
<add key=“Key0” value=“0” />
<add key=“Key1” value=“1” />
<add key=“Key2” value=“2” />
</appSettings>
</configuration>
In Solution Explorer, double-click Program.cs to display the code window. Add
the following statements to your code module.
Note These statements must appear before any other statements in the
file.
using System.Configuration;
using System.Collections.Specialized;
Add a reference to System.Configuration.dll. To do this, follow these steps:
On the Project menu, click Add Reference.
In the Add Reference dialog box, click the .NET tab.
Find and select the Component Name of System.Configuration.
Click OK.
To hold the value from a configuration file key in the <appSettings>
section of the configuration file, declare a string variable in the Main section
as follows:
string sAttr ;
To retrieve a value for a specified key from the <appSettings> section of
the configuration file, use the Get method of the AppSettings property of the
ConfigurationManager class. The ConfigurationManager class is in the
System.Configuration namespace. When the AppSettings.Get method receives a
string input parameter that contains a key, the application retrieves the value
that is associated with the key.
The following code retrieves the value for the Key0 attribute from the
associated configuration file. The code then places this value in the sAttr
string variable. If a key does not exist for this value, nothing is stored in
sAttr.
sAttr = ConfigurationManager.AppSettings.Get(“Key0”);
To display the value that the application retrieves in the Console window, use
Console.WriteLine as follows:
Console.WriteLine("The value of Key0 is "+sAttr);
You can use one reference to the AppSettings property to retrieve all the
key/value pairs in the<appSettings> section. When you use the AppSettings
property, the application returns all associated key/value pairs. These pairs
are stored in a NameValueCollection type. The NameValueCollection contains
key/value entries for each key that the application retrieves. The
NameValueCollection class is in the System.Collections.Specialized
namespace.
NameValueCollection sAll ;
sAll = ConfigurationManager.AppSettings;
The AllKeys property of NameValueCollection references a string array that has
an entry for each key that the application retrieves. Use a foreach construction
to iterate through the AllKeys array to access each key that the application
retrieves. Each key entry in AllKeys is a string data type.
Inside the foreach construction, use Console.WriteLine to display the key and
its associated value in the Console window. The current key that the application
processes is in “s”. Use this as an index in the sAllNameValueCollection to
obtain its associated value.
foreach (string s in sAll.AllKeys)
Console.WriteLine("Key: "+ s + " Value: " + sAll.Get(s));
Console.ReadLine();
app.constant(‘myAppConfig’, {ver: ‘1.2.2’, bananas: 6, hammocks: 3,
bananaHammocks: true});
This is not a whole lot different from Terry's solution, but constants don't
change so they are applied before the other providers. Also, this module can be
injected into your config function.
app.config(function(myAppConfig){
console.log(myAppConfig.bananaHammocks);
});
informatica training in chennai | hadoop training in chennai | aws training in chennai