0.1.0-beta.3 • Published 11 months ago
@alliage/parameters-loader v0.1.0-beta.3
Alliage Parameters Loader
Provides a generic configuration file to store any parameters we could need to configure our application.
Dependencies
Installation
yarn add @alliage/parameters-loader
With npm
npm install @alliage/parameters-loader
Registration
If you have already installed @alliage/module-installer you just have to run the following command:
$(npm bin)/alliage-scripts install @alliage/parameters-loader
Otherwise, update your alliage-modules.json
file to add this at the bottom:
{
// ... other modules
"@alliage/parameters-loader": {
"module": "@alliage/parameters-loader",
"deps": [
"@alliage/lifecycle",
"@alliage/di",
"@alliage/module-installer",
"@alliage/config-loader"
],
"envs": [],
}
}
Usage
Once installed, a new file located in config/parameters.yaml
should be available.
The format of this file is totally free.
For example we could have something like that:
# config/parameters.yaml
webserver:
host: 127.0.0.1
port: 8080
credentials:
username: thehumblejester
password: '411!463|20(|(5'
Then, everything would be available as a dependency of any service as in the following example:
import { AbstractLifeCycleAwareModule, INIT_EVENTS, RUN_EVENTS } from '@alliage/lifecycle';
import { parameter } from '@alliage/di';
import { MyService } from './MyService';
export = class MyModule extends AbstractLifeCycleAwareModule {
// ...
registerServices(serviceContainer) {
serviceContainer.registerService('my_service', MyService, [
parameter('parameters.webserver.host'),
parameter('parameters.webserver.port'),
parameter('parameters.webserver.credentials'),
]);
}
}