registerAsync<T extends Object> method

void registerAsync<T extends Object>(
  1. Future<T> fn(), {
  2. String? name,
})

Registers a lazily initialized asynchronous dependency in the dependency injection container.

The provided function fn must return a Future<T>, where T is the type of the dependency. The dependency initialization will only occur when it is first requested.

  • T: The type of the dependency being registered.
  • fn: A function that returns a Future<T> which initializes the dependency.
  • name: An optional string to identify the dependency. This is useful for distinguishing between multiple instances of the same type.

Example:

diPlugin.registerAsync<MyService>(() async {
  return MyService();
}, name: 'myService');

Implementation

void registerAsync<T extends Object>(Future<T> Function() fn,
        {String? name}) =>
    registerLazy<Future<T>>(fn, name: name);