dain 0.1.1 copy "dain: ^0.1.1" to clipboard
dain: ^0.1.1 copied to clipboard

A dynamic dependency injection framework for Dart developers.

example/example.dart

import 'package:dain/bean/bean.dart';
import 'package:dain/dain.dart';
import 'package:dain/module/module.dart';

void main() {
  Dain.start([
    ExampleModule(),
  ]);

  Dain.inject<ExampleService>().sayHello(); // print "Hello World!"
}

abstract class ExampleService {
  void sayHello();
}

//Implementation class
class ExampleServiceImpl extends ExampleService {
  @override
  void sayHello() {
    print('Hello World!');
  }
}

//Bean registration class
class ExampleModule extends Module {
  @override
  List<Bean> register() {
    return [
      single<ExampleService>(() => ExampleServiceImpl()),
    ];
  }
}
0
likes
140
pub points
0%
popularity

Publisher

verified publisherkazakago.com

A dynamic dependency injection framework for Dart developers.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

More

Packages that depend on dain