Last updated:
0 purchases
pip services4 logic
Business Logic definitions for Dart #
This module is a part of the Pip.Services polyglot microservices toolkit.
The Logic module contains standard component definitions to handle complex business transactions.
The module contains the following packages:
Cache - distributed cache
Lock - distributed lock components
State - distributed state management components
Quick links:
Logging
Configuration
API Reference
Change Log
Get Help
Contribute
Examples
Use #
Add this to your package's pubspec.yaml file:
dependencies:
pip_services4_logic: version
copied to clipboard
Now you can install package from the command line:
pub get
copied to clipboard
Example how to use caching and locking.
Here we assume that references are passed externally.
import 'package:pip_services4_commons/src/refer/Descriptor.dart';
import 'package:pip_services4_commons/src/refer/References.dart';
import 'package:pip_services4_commons/src/refer/IReferences.dart';
import 'package:pip_services4_commons/src/refer/IReferenceable.dart';
import 'package:pip_services4_logic/src/lock/ILock.dart';
import 'package:pip_services4_logic/src/lock/MemoryLock.dart';
import 'package:pip_services4_logic/src/cache/ICache.dart';
import 'package:pip_services4_logic/src/cache/MemoryCache.dart';
class MyComponent implements IReferenceable {
ICache? _cache;
ILock? _lock;
@override
void setReferences(IReferences refs) {
_cache =
refs.getOneRequired<ICache>(Descriptor('*', 'cache', '*', '*', '1.0'));
_lock =
refs.getOneRequired<ILock>(Descriptor('*', 'lock', '*', '*', '1.0'));
}
Future myMethod(IContext? context, dynamic param1) async {
// First check cache for result
dynamic result = await _cache!.retrieve(context, 'mykey');
// Lock..
await _lock!.acquireLock(context, 'mykey', 1000, 1000);
// Do processing
// ...
// Store result to cache async
await _cache!.store(context, 'mykey', result, 3600000);
// Release lock async
await _lock!.releaseLock(context, 'mykey');
}
}
void main() async {
// Use the component
MyComponent myComponent = MyComponent();
myComponent.setReferences(References.fromTuples([
Descriptor('pip-services', 'cache', 'memory', 'default', '1.0'),
MemoryCache(),
Descriptor('pip-services', 'lock', 'memory', 'default', '1.0'),
MemoryLock(),
]));
await myComponent.myMethod(null, 'param1');
}
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.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.