Skip to main content

angel3_container_generator 10.0.0 copy "angel3_container_generator: ^10.0.0" to clipboard
angel3_container_generator: ^10.0.0 copied to clipboard

Generates the reflection data Angel3's container needs to construct @injectable classes, so it works without dart:mirrors (e.g. in AOT-compiled apps).

example/main.dart

/// Constructor injection without `dart:mirrors`, so this program can be
/// AOT-compiled:
///
/// ```sh
/// dart run build_runner build
/// dart compile exe example/main.dart -o greeter
/// ```
library;

import 'package:angel3_container/angel3_container.dart';

part 'main.g.dart';

@injectable
class Config {
  final String greeting;

  Config([this.greeting = 'Hello']);
}

@injectable
class Greeter {
  final Config config;
  final String punctuation;

  Greeter(this.config, {this.punctuation = '!'});

  String greet(String name) => '${config.greeting}, $name$punctuation';
}

void main() {
  var container = Container(StaticReflector.combine([mainReflection]));
  print(container.make<Greeter>().greet('world'));

  container
    ..registerSingleton(Config('Hi'))
    ..registerSingleton<String>('?');
  print(container.make<Greeter>().greet('AOT'));
}
1
likes
160
points
540
downloads

Documentation

API reference

Publisher

verified publisherdukefirehawk.com

Weekly Downloads

Generates the reflection data Angel3's container needs to construct @injectable classes, so it works without dart:mirrors (e.g. in AOT-compiled apps).

Homepage
Repository (GitHub)
View/report issues
Contributing

License

BSD-3-Clause (license)

Dependencies

analyzer, angel3_container, build, path, source_gen

More

Packages that depend on angel3_container_generator