catalyst 3.0.0 copy "catalyst: ^3.0.0" to clipboard
catalyst: ^3.0.0 copied to clipboard

discontinuedreplaced by: catalyst_builder
SDKDart

The only dependency injection container for Dart you'll ever need

example/main.dart

/*
 * This file is part of the Catalyst package.
 *
 * Copyright 2018-present by Julian Finkler <julian@mintware.de>
 *
 * For the full copyright and license information, please read the LICENSE
 * file that was distributed with this source code.
 */

import 'package:catalyst/catalyst.dart';

void main() {
  var container = Container();

  // Register the StackAsAService in the container
  container.register('shared_stack', StackAsAService);

  // Get the registered service from the container
  StackAsAService stack = container.get('shared_stack');

  // Modify the stack
  print(stack.length); // Outputs 0

  stack.add('Hello');
  stack.add('World');

  print(stack.length); // Outputs 2

  print(stack.entries); // Outputs [Hello, World]

  // Retrieve the  same service again from the container
  StackAsAService anotherStack = container.get('shared_stack');

  print(anotherStack.length); // Outputs 2

  print(anotherStack.entries); // Outputs [Hello, World]

  // Modify it...
  anotherStack.remove('World');

  // And the first variable is also modified
  print(stack.length); // Outputs 2

  print(stack.entries); // Outputs [Hello]
}

class StackAsAService {
  final _entries = <String>[];

  void add(String entry) {
    _entries.add(entry);
  }

  void remove(String entry) {
    _entries.removeWhere((e) => e == entry);
  }

  List<String> get entries => _entries;

  int get length => _entries.length;
}
1
likes
150
points
61
downloads

Publisher

verified publishermintware.de

Weekly Downloads

The only dependency injection container for Dart you'll ever need

Repository (GitHub)

Documentation

API reference

License

MIT (license)

More

Packages that depend on catalyst