pip_services4_logic 0.0.2 copy "pip_services4_logic: ^0.0.2" to clipboard
pip_services4_logic: ^0.0.2 copied to clipboard

Logic Components for Pip.Services in Dart. This framework is part of the [Pip.Services](https://github.com/pip-services/pip-services) project.

Pip.Services Logo
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:

Use #

Add this to your package's pubspec.yaml file:

dependencies:
  pip_services4_logic: version

Now you can install package from the command line:

pub get

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');
}

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.

0
likes
130
pub points
0%
popularity

Publisher

verified publisherentinco.com

Logic Components for Pip.Services in Dart. This framework is part of the [Pip.Services](https://github.com/pip-services/pip-services) project.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

pip_services4_commons, pip_services4_components

More

Packages that depend on pip_services4_logic