@quandis/qbo4.configuration 4.0.1-CI-20240328-123132 → 4.0.1-CI-20240406-131017
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -2
- package/readme.md +80 -6
- package/scss/qbo-config-editor.scss +2 -0
- package/wwwroot/css/qbo-config-editor.css +3 -0
- package/wwwroot/css/qbo-config-editor.css.map +1 -0
- package/wwwroot/css/qbo-config-editor.min.css +0 -0
- package/wwwroot/js/qbo4.configuration.js +15 -9
- package/wwwroot/js/qbo4.configuration.min.js +1 -1
- package/wwwroot/js/qbo4.configuration.min.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quandis/qbo4.configuration",
|
|
3
|
-
"version": "4.0.1-CI-
|
|
3
|
+
"version": "4.0.1-CI-20240406-131017",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./src/Program.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"wwwroot/js/",
|
|
13
|
-
"
|
|
13
|
+
"wwwroot/css/",
|
|
14
|
+
"src/",
|
|
15
|
+
"scss/"
|
|
14
16
|
],
|
|
15
17
|
"dependencies": {
|
|
16
18
|
"bootstrap": "^5.3.3",
|
package/readme.md
CHANGED
|
@@ -1,11 +1,85 @@
|
|
|
1
|
-
|
|
1
|
+
# Overview
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `@quandis/qbo4.Configuration.Web` package offers javascript classes to manage configuration settings for a web application.
|
|
4
|
+
It is pattered on Microsoft's `IConfiguration` patterns and extensions.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Including the `qbo4.Configuration.js` script will provide:
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
`qbo4.services`: a container for dependency injection (including `qbo4.services.container` for direct access to the `tsyringe` container)
|
|
9
|
+
`qbo4.configuration`: a set of classes to manage configuration settings
|
|
10
|
+
`IConfiguration`: an interface to manage configuration settings
|
|
11
|
+
|
|
12
|
+
It provides for dependency injections via the `tsyringe` package.
|
|
13
|
+
|
|
14
|
+
# Typescript Usage
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import 'reflect-metadata';
|
|
18
|
+
import { Configuration, IConfiguration, IConfigurationSource, IConfigurationSourceToken, IConfigurationToken, JsonConfigurationSource, services } from '@quandis/qbo4.configuration';
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class OptionsA { public name: string = ''; }
|
|
22
|
+
class OptionsB { public count: number = 0; }
|
|
23
|
+
|
|
24
|
+
const source1 = new JsonConfigurationSource({ A: { name: 'Alice' }, B: { count: 27 } });
|
|
25
|
+
const source2 = new JsonConfigurationSource({ A: { name: 'Bob' }, C: { enabled: true } });
|
|
26
|
+
services.container.register<IConfigurationSource>(IConfigurationSourceToken, { useValue: source1 });
|
|
27
|
+
services.container.register<IConfigurationSource>(IConfigurationSourceToken, { useValue: source2 });
|
|
28
|
+
|
|
29
|
+
const config: IConfiguration = services.container.resolve<IConfiguration>(IConfigurationToken);
|
|
30
|
+
expect(config).not.null;
|
|
31
|
+
const a = config.getSection('A').bind(OptionsA);
|
|
32
|
+
expect(a.name).equal('Bob');
|
|
33
|
+
|
|
34
|
+
const b = config.getSection('B').bind(OptionsB);
|
|
35
|
+
expect(b.count).equal(27);
|
|
10
36
|
```
|
|
11
37
|
|
|
38
|
+
# Browser Usage
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<html>
|
|
42
|
+
<head>
|
|
43
|
+
<script src="//configuration/js/qbo4.Configuration.js"></script>
|
|
44
|
+
<script type="text/javascript">
|
|
45
|
+
const aiConfig = new qbo4.logging.JsonConfigurationSource({ 'ApplicationInsights': { instrumentationKey: '651cc99f-0b30-4f27-8918-e53dfed1a2c2' } });
|
|
46
|
+
qbo4.services.container.register(qbo4.logging.IConfigurationSourceToken, { useValue: aiConfig });
|
|
47
|
+
// now the configuration settings are available for dependency injection
|
|
48
|
+
|
|
49
|
+
// later in your code, web components, or scripts:
|
|
50
|
+
const instances = qbo4.services.container.resolveAll<SomeInterface>(SomeInterfaceToken);
|
|
51
|
+
|
|
52
|
+
</script>
|
|
53
|
+
</head>
|
|
54
|
+
<body>
|
|
55
|
+
</body>
|
|
56
|
+
</html>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
# Example: ApplicationInsights Logger
|
|
60
|
+
|
|
61
|
+
Assume we want to inject an `ApplicationInsights` logger, where the `InstrumentationKey` is stored in the configuration settings.
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// An options class
|
|
65
|
+
export class ApplicationInsightsOptions {
|
|
66
|
+
public InstrumentationKey: string = '';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Prepare the options for dependency injection (a tsyring pattern)
|
|
70
|
+
export const ApplicationInsightsOptionsToken: InjectionToken<ApplicationInsightsOptions> = 'ApplicationInsightsOptions';
|
|
71
|
+
|
|
72
|
+
// The logger class
|
|
73
|
+
@injectable()
|
|
74
|
+
export class ApplicationInsights {
|
|
75
|
+
constructor(
|
|
76
|
+
@inject(ApplicationInsightsOptionsToken) private options: ApplicationInsightsOptions
|
|
77
|
+
) {
|
|
78
|
+
// Initialize the logger
|
|
79
|
+
// ...
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Prepare the class for dependency injection
|
|
84
|
+
export const ApplicationInsightsToken: InjectionToken<ApplicationInsights> = 'ApplicationInsights';
|
|
85
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"qbo-config-editor.css"}
|
|
File without changes
|