cobalt_generator 0.1.2 copy "cobalt_generator: ^0.1.2" to clipboard
cobalt_generator: ^0.1.2 copied to clipboard

Code generator for Cobalt. Emits the container, property-injection mixins and the two-phase startup. Use as a dev_dependency.

example/example.md

cobalt_generator example #

A dev_dependency — it never ships in an application.

dev_dependencies:
  cobalt_generator: ^0.1.0
  build_runner: ^2.15.0
dart run build_runner build

All three builders are auto_apply: dependents, so declaring the dependency is the whole setup. From this:

@cobaltInject
class Repository {
  Repository(this.database);
  final Database database;
}

it writes lib/cobalt.g.dart with a named const factory class — never a closure — and a $CobaltRootScope whose registrations are ordered by a compile-time topological sort:

final class _RepositoryFactory implements CobaltFactory<Repository> {
  const _RepositoryFactory();

  @override
  Repository create(CobaltResolver resolver) => Repository(resolver.get<Database>());
}

Start it with the generated $startCobalt(), or hand the pieces to CobaltAppScope. A dependency cycle fails the build naming the cycle instead of emitting code that would deadlock.

Full setup: examples/codegen_basics.

0
likes
150
points
196
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Code generator for Cobalt. Emits the container, property-injection mixins and the two-phase startup. Use as a dev_dependency.

Repository (GitHub)
View/report issues

Topics

#dependency-injection #codegen #build-runner #di

License

MIT (license)

Dependencies

analyzer, build, cobalt_analyzer, cobalt_annotations, code_builder, collection, dart_style, glob, path, source_gen

More

Packages that depend on cobalt_generator