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

discontinuedreplaced by: catalyst_builder
outdatedDart 1 only

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

example/main.dart

/*
 * This file is part of the Catalyst package.
 *
 * Copyright 2018 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';

main() {
  Container container = new 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 {
  List<String> _entries = new List<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
0
pub points
0%
popularity

Publisher

verified publishermintware.de

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

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on catalyst