Dependency Injection via Context | RepositoryProvider | Flutter App from Scratch #17

Опубликовано: 29 Август 2026
на канале: Стас Ильин
2,854
77

Dependency Injection is one of the most important mechanisms in modern development. It's crucial to manage your project's dependencies in a safe and predictable manner.

In Flutter, context remains the primary tool for dependency injection. And thanks to the Bloc library and the built-in RepositoryProvider, we can inject dependencies not only safely but also easily and quickly.

How to do this, set up project configuration, and even decompose the logic so you can show it to your team leader without embarrassment—watch this video!

FOLLOW ME:
💬 Telegram https://t.me/frezycode
🚀 Exclusive content on Boosty https://boosty.to/frezycode
👨‍💻 Tons of code on GitHub https://github.com/Frezyx
📸 Instagram   / frezycode  

WE'RE WRITING A BOOK ON FLUTTER
📖 Learn more about the book https://t.me/frezycode/354
💻 Stepik course https://stepik.org/a/197817/pay?promo...

CODE FROM THE VIDEO
Project Github https://github.com/Frezyx/rhymer

00:00 - What will happen in the video?
00:21 - What is a RepositoryProvider
00:46 - Differences from get_it and service locator
01:25 - Problems with the get_it package
01:45 - Pros of constructor injection
02:17 - Cons of RepositoryProvider
02:23 - Should I choose get_it or RepositoryProvider?
03:09 - How to simplify main.dart
04:07 - MultiRepositoryProvider
04:26 - Adding a RepositoryProvider
06:00 - How to get a RepositoryProvider from context
07:51 - Registering in context by abstraction type
09:07 - Which type do we register by and get it?
10:14 - How to configure application startup
12:14 - Writing the AppConfig configuration class
13:16 - How to pass dependencies to an application
14:15 - Why split main.dart into different files?
15:34 - How to quickly add imports
16:12 - Splitting MaterialApp into configuration and startup
16:36 - Creating the app module
19:28 - How much clearer is the code after refactoring?
20:18 - What else can be refactored?
21:27 - Simplifying dependency initialization logic