force_inject 0.2.0 copy "force_inject: ^0.2.0" to clipboard
force_inject: ^0.2.0 copied to clipboard

A zero-dependency DI container for Dart, inspired by .NET Core. This is the Way.

πŸ”Œ ForceInject #

pub package publisher: diegogarcia.ca

πŸ› οΈ 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 singleton and transient lifetimes
  • 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 #

Patreon

Or make a donation buying me a coffee:

Buy 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. βš”οΈ

1
likes
0
points
59
downloads

Publisher

verified publisherdiegogarcia.ca

Weekly Downloads

A zero-dependency DI container for Dart, inspired by .NET Core. This is the Way.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

meta

More

Packages that depend on force_inject