force_inject 0.2.0
force_inject: ^0.2.0 copied to clipboard
A zero-dependency DI container for Dart, inspired by .NET Core. This is the Way.
π ForceInject #
π οΈ A lightweight, zero-dependency Dependency Injection (DI) container for Dart.
π Inspired by .NET Core and powered by the Force.
This is the Way.
β¨ Features #
- Constructor-based dependency injection
- Support for
singletonandtransientlifetimes - Zero dependencies β pure Dart
- No code generation, no mirrors
- Inspired by C#/.NET Core DI patterns
- Lightweight, test-friendly, and easy to integrate
π Getting Started #
1. Register your services #
final services = ServiceCollection();
services.addSingleton<ILogger, ConsoleLogger>();
services.addTransient<UserService, UserService>();
ServiceProvider.registerConstructor<ConsoleLogger>(() => ConsoleLogger(), []);
ServiceProvider.registerConstructor<UserService>(
(ILogger logger) => UserService(logger),
[ILogger],
);
2. Build the provider #
final provider = services.buildServiceProvider();
3. Resolve services #
final userService = provider.get<UserService>();
userService.sayHello(); // [LOG]: Hello from UserService!
βοΈ Lifetimes #
| Type | Description |
|---|---|
singleton |
One shared instance across the application |
transient |
A new instance is created every time |
π¦ Why ForceInject? #
Dart is an elegant language, but backend structure is still evolving.
ForceInject gives you the power of .NETβs DI model, but in pure Dart β making your code modular, testable, and maintainable.
No magic. No mirrors. Just clean, focused architecture.
π¬ "When your services are confused, inject them you must." β Yodart
π§ͺ Examples & Playground #
Check out the example/ folder for more real-world setups.
Support me (@diegomgarcia) with Patreon #
Or make a donation buying me a coffee:
You can also show support by showing on your repository that you use this lib on it with a direct link to it.
π License #
MIT β Free to use, modify, or extend.
May the DI be with you. βοΈ

