pip_services4_config 0.0.2 pip_services4_config: ^0.0.2 copied to clipboard
Config Components for Pip.Services in Dart. This framework is part of the [Pip.Services](https://github.com/pip-services/pip-services) project.
Config components definitions for Dart #
This module is a part of the Pip.Services polyglot microservices toolkit.
The Config module contains configuration component definitions that can be used to build applications and services.
The module contains the following packages:
- Auth - authentication credential stores
- Config - configuration readers and managers, whose main task is to deliver configuration parameters to the application from wherever they are being stored
- Connect - connection discovery and configuration services
-
Warning! Config package now not work with condition {{#if var}} something {{/}} in config files. Use Mustache syntax, for example {{#var}} something {{/var}}
Use #
Add this to your package's pubspec.yaml file:
dependencies:
pip_services4_config: version
Now you can install package from the command line:
pub get
Example how to get connection parameters and credentials using resolvers. The resolvers support "discovery_key" and "store_key" configuration parameters to retrieve configuration from discovery services and credential stores respectively.
import 'package:pip_services4_commons/src/config/ConfigParams.dart';
import 'package:pip_services4_commons/src/config/IConfigurable.dart';
import 'package:pip_services4_commons/src/refer/IReferences.dart';
import 'package:pip_services4_commons/src/refer/IReferenceable.dart';
import 'package:pip_services4_commons/src/run/IOpenable.dart';
import 'package:pip_services4_config/src/connect/ConnectionParams.dart';
import 'package:pip_services4_config/src/connect/ConnectionResolver.dart';
import 'package:pip_services4_config/src/auth/CredentialParams.dart';
import 'package:pip_services4_config/src/auth/CredentialResolver.dart';
class MyComponent implements IConfigurable, IReferenceable, IOpenable {
final _connectionResolver = ConnectionResolver();
final _credentialResolver = CredentialResolver();
bool _opened = false;
@override
void configure(ConfigParams config) {
_connectionResolver.configure(config);
_credentialResolver.configure(config);
}
@override
void setReferences(IReferences refs) {
_connectionResolver.setReferences(refs);
_credentialResolver.setReferences(refs);
}
// ...
@override
Future open(IContext? context) async {
ConnectionParams? connection =
await _connectionResolver.resolve(context);
CredentialParams? credential =
await _credentialResolver.lookup(context);
if (connection != null && credential != null) {
String? host = connection.getHost();
int? port = connection.getPort();
String? user = credential.getUsername();
String? pass = credential.getPassword();
// ...
_opened = true;
}
}
}
// Using the component
var myComponent = new MyComponent();
myComponent.configure(ConfigParams.fromTuples(
'connection.host', 'localhost',
'connection.port', 1234,
'credential.username', 'anonymous',
'credential.password', 'pass123'
));
await myComponent.open(null);
Develop #
For development you shall install the following prerequisites:
- Dart SDK 3
- Visual Studio Code or another IDE of your choice
- Docker
Install dependencies:
pub get
Run automated tests:
pub run test
Generate API documentation:
./docgen.ps1
Before committing changes run dockerized build and test as:
./build.ps1
./test.ps1
./clear.ps1
Contacts #
The library is created and maintained by Sergey Seroukhov and Levichev Dmitry.
The documentation is written by Egor Nuzhnykh, Alexey Dvoykin, Mark Makarychev, Levichev Dmitry.