This is an experimental feature and subject to change
Wiretaps lifecycle feature can be enabled to allow for initializers to be provided to do any kind of work on startup. Dispose listeners can be registered to do the same before disposing.
Enable the lifecycle#
WiretapContext(providers: [
provideExperimentalLifecycleApi(),
]);
Initializing#
To provide a callback for initializing something do:
final context = WiretapContext(providers: [
provideInitializer((inject) => inject(fooService).fetchData())
]);
To actually do the initialization do:
runInitializers(context.inject);
This is typically beeing done right after the WiretapContext has been initialized.
DisposeRef#
To register a callback for disposing something do:
final fooServiceToken = createToken((inject) {
final service = FooService();
inject(disposeRef).onDispose(() => service.dispose());
return service;
});
To actually trigger the dispose listeners do:
runDisposeListeners(context.inject);
This is typically beeing done right before the WiretapContext is disposed.
This api is built on top of wiretaps public api and could be implemented entirely by the consumer (you). This api exists solely because lifecycle management is important for many projects and wiretap should provide a general way to do that. Feel free to create your own variant of this api to make it better suit your needs.
Next: Start using wiretap with Flutter.