A powerful code-generation dependency injection toolkit for Dart & Flutter built on top of GetIt.
It automates service locator registration, manages asynchronous dependency resolution, isolates modular domains via Folder-Scoped Micro-Packages, and supports seamless multi-package monorepo architectures.
Full documentation, interactive architecture diagrams, tutorials, and API reference are available at:
https://chornthorn.github.io/injectify-dart/
- Code-Generated Registrations: Annotate, run
build_runner, and get a typed GetItinit()— constructor parameters resolve from the container. - Folder-Scoped Micro-Packages:
@InjectableMicroPackage(moduleName: 'Feature')isolates a folder into its own module. Nested sub-modules auto-compose viauseMicroPackage: true(each module is composed exactly once). - Root Compositor:
@InjectableInit(useMicroPackage: true)discovers all folder micro-packages and registers them flatly at the root container. - External Module Composition:
externalMicroPackages: [ExternalMicroPackage(ModuleType)]composes modules from other packages (other pubspecs) in declaration order — no manualgetIt.initX()wiring. - Scopes: Unified
@Injectable(scope: Scope.singleton | Scope.lazySingleton | Scope.factory). - Async & Tagged Registrations:
@PreResolve/Futurefactories emitsingletonAsync;@Inject('tag')emits named GetIt lookups. - Environment Gating:
@Environment('dev')/env: [Environment.dev]registers only for matching environments viaEnvironmentFilter.
This repository ships with a standard Agent Skill conforming to the Agent Skills specification located in skills/injectify/.
Developers using AI assistants (Claude Code, Cursor, Antigravity, GitHub Copilot, Codex, etc.) can equip their agents with full Injectify expertise by copying or downloading the skill into their project:
# In your Dart/Flutter project directory:
mkdir -p .agents/skills/injectify
cp -r /path/to/injectify-dart/skills/injectify/* .agents/skills/injectify/The skill includes complete guidance for:
- Automatic DI setup a
93BC
nd code generation (
build_runner) - Modern annotations (
@Injectable,@InjectableInit,@InjectableMicroPackage,@ExternalModule,@Inject,@FactoryParam,@PreResolve) - Folder micro-packages and multi-package monorepos
- Ready-to-use templates for
injection.dart, micro-packages, andbuild.yaml
The documentation is organized into four core pillars:
- Getting Started: Installation, initial configuration,
build_runnerworkflows, and quickstart tutorials. - Core Concepts: Deep dives into dependency injection mechanics, lifetimes, micro-package isolation, asynchronous startup (
@PreResolve), and environment gating. - How-To Tasks: Step-by-step recipes for custom disposal hooks, parameterized factories, third-party module registration, and cross-package linking.
- API Reference: Exhaustive specifications for all annotations, CLI builder options, diagnostic error codes, and glossary definitions.
Add the runtime annotations to dependencies and the code generator to dev_dependencies:
dependencies:
get_it: ^9.2.1
injectify: ^0.1.0
dev_dependencies:
build_runner: ^2.4.0
injectify_generator: ^0.1.0import 'package:injectify/injectify.dart';
@Injectable(scope: Scope.lazySingleton)
class ApiService {
final String baseUrl;
ApiService({this.baseUrl = 'https://api.example.com'});
}
@Injectable(scope: Scope.factory)
class UserRepository {
final ApiService api;
UserRepository(this.api);
}import 'package:get_it/get_it.dart';
import 'package:injectify/injectify.dart';
import 'main.config.dart';
final getIt = GetIt.instance;
@InjectableInit()
Future<void> configureDependencies() async => getIt.init();
void main() async {
await configureDependencies();
final repo = getIt<UserRepository>();
print('UserRepository initialized with API: ${repo.api.baseUrl}');
}# Dart
dart run build_runner build --delete-conflicting-outputsFor large scale codebases, decompose your feature modules using Folder Micro-Packages:
lib/
├── features/
│ ├── auth/
│ │ ├── auth_service.dart # Annotated with @Injectable()
│ │ └── auth_module.dart # Annotated with @InjectableMicroPackage(moduleName: 'Auth')
│ └── catalog/
│ ├── catalog_service.dart # Annotated with @Injectable()
│ └── catalog_module.dart # Annotated with @InjectableMicroPackage(moduleName: 'Catalog')
└── main.dart # Annotated with @InjectableInit(useMicroPackage: true)
Run build_runner once at the root: each feature generates its own isolated module initialization extension, and the root init() orchestrates the entire container tree cleanly.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.