force_inject_provider 0.1.0
force_inject_provider: ^0.1.0 copied to clipboard
Provider integration for ForceInject — a lightweight dependency injection container for Dart and Flutter.
🧩 force_inject_provider #
A plugin that integrates the ForceInject DI container with the popular Provider package in Flutter.
🛠️ Easily create scoped dependency injection and reactive
ChangeNotifier
ViewModels.
✨ Features #
- ✔️
ProviderScope
to manage lifecycle-aware DI scopes - ✔️
ProviderNotifierBuilder<T>
to inject and listen toChangeNotifier
s - ✔️ Automatically disposes ViewModels
- ✔️ Clean integration with
force_inject
🚀 Getting Started #
1. Define your services: #
final services = ServiceCollection();
services.addScoped<CounterViewModel, CounterViewModel>();
ServiceProvider.registerConstructor<CounterViewModel>(
() => CounterViewModel(),
[],
);
final provider = services.buildServiceProvider();
2. Wrap your app or page in a ProviderScope
: #
return ProviderScope(
create: () => provider.createScope(),
child: MyApp(),
);
3. Use ProviderNotifierBuilder<T>
to inject your ViewModel: #
ProviderNotifierBuilder<CounterViewModel>(
builder: (context, viewModel, _) => Text('${viewModel.count}'),
)
📦 Example #
See example/minimal_provider_di
for a full working Flutter app.
📜 License #
MIT — Free to use, modify, and distribute.