talira

injectable

Code generator that wires up get_it dependency injection in Dart and Flutter

open sourceMITfree

injectable is a code generator for get_it, the Dart and Flutter service locator. You annotate classes with @injectable, @singleton or @lazySingleton, and injectable_generator writes the get_it registration code for them, so you don't register each dependency by hand. It handles asynchronous dependencies, factory parameters, binding abstract classes to implementations, environments, named instances, scopes and third-party types, and runs on build_runner or, experimentally, lean_builder. Its makers say it was inspired by Angular DI, Guice and inject.dart.

Problems it solves

  • stop registering every dependency with get_it by hand in my Flutter app
  • generate dependency injection code from annotations in Dart
  • register different implementations for dev and production in a Flutter app

Features

  • generates get_it registration code from annotations
  • singletons and lazy singletons, with dispose methods
  • asynchronous injectables and pre-resolved futures
  • factory parameters
  • bind abstract classes to implementations
  • register under different environments
  • scopes and micro-packages
  • build_runner or experimental lean_builder support

Alternatives

The same job

These do what injectable does.

  1. get_it A simple, fast service locator for Dart and Flutter

Compare injectable with the top 3