pip_services4_components

Last updated:

0 purchases

pip_services4_components Image
pip_services4_components Images
Add to Cart

Description:

pip services4 components

Portable Component Model for Dart #
This module is a part of the Pip.Services polyglot microservices toolkit.
It defines a portable component model interfaces and provides utility classes to handle component lifecycle.
The module contains the following packages:

Build - basic factories for constructing objects
Config - configuration pattern
Refer - locator inversion of control (IoC) pattern
Run - component life-cycle management patterns

Quick links:


Logging


Configuration


API Reference


Change Log


Get Help


Contribute


Examples


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_components: version
copied to clipboard
Now you can install package from the command line:
pub get
copied to clipboard
Then you are ready to start using the Pip.Services patterns to augment your backend code.
For instance, here is how you can implement a component, that receives configuration, get assigned references,
can be opened and closed using the patterns from this module.
class MyComponentA implements IConfigurable, IReferenceable, IOpenable {
MyComponentA();

String _param1 = 'ABC';
int _param2 = 123;
MyComponentB _anotherComponent;
bool _opened = true;

@override
void configure(ConfigParams config) {
this._param1 = config.getAsStringWithDefault('param1', this._param1);
this._param2 = config.getAsIntegerWithDefault('param2', this._param2);
}

@override
void setReferences(IReferences refs) {
this._anotherComponent = refs.getOneRequired<MyComponentB>(
Descriptor('myservice', 'mycomponent-b', '*', '*', '1.0')
);
}

@override
bool isOpen() {
return this._opened;
}

@override
Future open(IContext? context) {
return Future(() {
this._opened = true;
print('MyComponentA has been opened.');
});
}

@override
Future close(IContext? context) {
return Future(() {
this._opened = true;
print('MyComponentA has been closed.');
});
}
}
copied to clipboard
Then here is how the component can be used in the code
import 'package:pip_services3_commons/src/config/ConfigParams.dart';
import 'package:pip_services3_commons/src/refer/References.dart';
import 'package:pip_services3_commons/src/refer/DependencyResolver.dart';

var myComponentA = MyComponentA();

// Configure the component
myComponentA.configure(ConfigParams.fromTuples([
'param1', 'XYZ',
'param2', 987
]));

// Set references to the component
myComponentA.setReferences(References.fromTuples([
Descriptor('myservice', 'mycomponent-b', 'default', 'default', '1.0',) myComponentB
]));

// Open the component
myComponentA.open(Context.fromTraceId('123'));
copied to clipboard
If you need to create components using their locators (descriptors) implement
component factories similar to the example below.
import 'package:pip_services3_components/src/build/Factory.dart';
import 'package:pip_services3_commons/src/refer/Descriptor.dart';

class MyFactory extends Factory {
static Descriptor myComponentDescriptor =
Descriptor('myservice', 'mycomponent', 'default', '*', '1.0');

MyFactory() : super() {
registerAsType(MyFactory.myComponentDescriptor, MyComponent);
}
}

// Using the factory

MyFactory myFactory = MyFactory();

MyComponent1 myComponent1 = myFactory.create(
Descriptor('myservice', 'mycomponent', 'default', 'myComponent1', '1.0'));
MyComponent2 myComponent2 = myFactory.create(
Descriptor('myservice', 'mycomponent', 'default', 'myComponent2', '1.0'));
...
copied to clipboard
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
copied to clipboard
Run automated tests:
pub run test
copied to clipboard
Generate API documentation:
./docgen.ps1
copied to clipboard
Before committing changes run dockerized build and test as:
./build.ps1
./test.ps1
./clear.ps1
copied to clipboard
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.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.