Skip to content

Commit c32210e

Browse files
committedDec 17, 2024·
added sections for Network, DI and Navigation plugins
1 parent 7a219b1 commit c32210e

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed
 

‎src/content/docs/guides/using-plugins.mdx

+39-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,45 @@ Future<GenresListResponse> genres() async {
277277

278278
## Using the `DIPlugin`
279279

280-
TBD
280+
Accessible via the `vyuh.di` API. The Di plug-in is useful for injecting shared
281+
dependencies within a feature or even across features. This is a core plugin
282+
that allows you to manage stores and services that are required within a feature
283+
or across features.
284+
285+
Typically, when you are building a feature, you would do all the DI
286+
registrations inside the `init()` method of the feature. This puts all the
287+
dependencies on the global DI container.
288+
289+
However, there might be situations where you would like to have the dependencies
290+
only use the scope of a single route. For such scenarios, you can use the Scoped
291+
DI, which is accessible inside the `RouteLifecycleConfiguration` for the route.
292+
The lifecycle handler is invoked during the `init()` and `dispose()` of
293+
individual routes, thus giving you a distinct time-boundary within which the
294+
dependencies are active. Note that the Scoped-DI Container for the Route is
295+
automatically reset when refreshing a route.
296+
297+
Depending on your needs, you can choose to put your dependencies on the global
298+
container or the scoped container.
299+
300+
Here is an example of the TMDB feature that uses the `init()` to register some
301+
feature-level dependencies:
302+
303+
```dart {8-10}
304+
final feature = FeatureDescriptor(
305+
name: 'tmdb',
306+
title: 'TMDB',
307+
description:
308+
'Uses the TMDB API to show details of movies with ability to favorite and add to watchlists',
309+
icon: Icons.movie_creation_outlined,
310+
init: () async {
311+
vyuh.di.register(TMDBClient(vyuh.env.get('TMDB_API_KEY')));
312+
vyuh.di.register(TMDBStore());
313+
vyuh.di.register(TmdbSearchStore());
314+
},
315+
316+
// rest of the feature config
317+
);
318+
```
281319

282320
## Using the `AuthPlugin`
283321

0 commit comments

Comments
 (0)