You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To be able to use `TJsonFileConfig` class with [dependency container](/dependency-container), Fano Framework provides `TJsonFileConfigFactory` class which enables you to register `TJsonFileConfig` class in container.
37
+
Load config from INI,
36
38
39
+
```
40
+
var config : IAppConfiguration;
41
+
...
42
+
config := TIniFileConfig.create(
43
+
getCurrentDir() + '/config/config.ini',
44
+
'fano'
45
+
);
46
+
```
47
+
Last parameter is name of default section to use. Read *INI file configuration* section in this document for more information.
48
+
49
+
To be able to use `TJsonFileConfig` and `TIniFileConfig` class with [dependency container](/dependency-container), Fano Framework provides `TJsonFileConfigFactory` and `TIniFileConfigFactory` class which enables you to register above classes in container.
50
+
51
+
Register JSON config
37
52
```
38
53
container.add(
39
54
'config',
@@ -43,6 +58,17 @@ container.add(
43
58
);
44
59
```
45
60
61
+
Register INI config
62
+
```
63
+
container.add(
64
+
'config',
65
+
TIniFileConfigFactory.create(
66
+
getCurrentDir() + '/config/config.ini'
67
+
)
68
+
);
69
+
```
70
+
71
+
46
72
To get configuration instance
47
73
48
74
```
@@ -97,6 +123,38 @@ var cookieMaxAge : integer;
97
123
cookieMaxAge := config.getInt('cookie.maxAge');
98
124
```
99
125
126
+
## INI file configuration
127
+
128
+
`TIniFileConfig` is thin wrapper of Free Pascal `TIniFile`. `TIniFile` cannot read data from INI file that has no section. Your INI file must contain at least one section which serve as default section. The last parameter of `TIniFileConfig`'s constructor expect name of default section. If you use `TIniFileConfigFactory`, by default it uses `fano` as default section if not specified. You can specify default section by calling `setDefaultSection()` method as shown in following code.
129
+
130
+
```
131
+
container.add(
132
+
'config',
133
+
TIniFileConfigFactory.create(
134
+
getCurrentDir() + '/config/config.ini'
135
+
).setDefaultSection('hello')
136
+
);
137
+
```
138
+
139
+
Consider reading `cookie.maxAge` configuration in code example above. It will read `maxAge` from `cookie` section.
140
+
141
+
```
142
+
[cookie]
143
+
maxAge=3600
144
+
```
145
+
146
+
However, because nested section are not allowed in INI file, you can only read on section. For example,
0 commit comments