Centralized modules configuration |
This topic contains the following sections:
To make it works correctly, AskiaPortalCmn require a
configuration file.
This configuration file must at least contains
the connection string to the AskiaPortal database.
In your ProgramData folder (C:\ProgramData\), create a file AskiaPortal.config under a sub-folder named AskiaPortal\.
The full path should look like that C:\ProgramData\AskiaPortal\AskiaPortal.config
This file centralize the configuration of AskiaPortal
for the entire machine.
So once the configuration is done,
it's done for all modules!
The content of the configuration file have the following format:
<configuration version="1.0"> <askiaportalcmn> <settings key="mainDatabase" value="Data Source=(local);Initial Catalog=AskiaPortal;Persist Security Info=True;Trusted_Connection=yes;" /> </askiaportalcmn> </configuration>
Where Key is:
Provide the SQL connection string to the AskiaPortal database
Extra keys for developers:
Provide the SQL connection string to the SQL Server master database (use to create/drop database within integration tests)
Provide the SQL connection string to an AskiaPortalTest database
Provide the key to obtain licenses for the unit tests
<configuration version="1.0"> <askiaportalcmn> <settings key="mainDatabase" value="Data Source=(local);Initial Catalog=AskiaPortal;Persist Security Info=True;Trusted_Connection=yes;" /> <settings key="masterDatabase" value="Data Source=(local);Initial Catalog=master;Persist Security Info=True;Trusted_Connection=yes;" /> <settings key="testDatabase" value="Data Source=(local);Initial Catalog=AskiaPortalTest;Persist Security Info=True;Trusted_Connection=yes;" /> <settings key="testLicensesKey"><![CDATA[SECRET]]></settings> </askiaportalcmn> </configuration>
Except for the connection string in the configuration file, the entire AskiaPortal configuration is stored into the database Config table.
Using the API, the configuration is accessible via a singleton instance of the Config.
The first call of ConfigGetInstance will read the configuration file and open the database according to the ConfigEnvironmentMode.
The Config class loads and contains all IConfigItem of all modules. This is very useful when a given module depends or uses the configuration of another module.
As AskiaPortal is itself consider as a module,
you can therefore access all his configuration.
As it's built-in there is a convenient accessors
that uses the ConfigKey
enumerator.
Most of the developers need to connect alternatively on a test database or on the production/development database.
To provide a quick switch between both databases, you first need to reference the test database connection string in the configuration file.
Secondly, the first call of the API must set the environment using the following line of code:
Config.SetEnvironment(Config.EnvMode.Test);