Recipes

Share async initialization

Use Async Lazy Singleton when concurrent callers need one shared initialized resource.

v0.1.0-dev.1Advancedark_di

Share async initialization

dart
binder.bindAsyncLazySingleton<Database>(
  (resolver) => Database.open(resolver.get<AppConfig>().databasePath),
  dispose: (database) => database.close(),
);

Concurrent getAsync<Database>() calls await one in-flight Future. A successful result is retained; a failed attempt is cleared so a later call can retry. Use Async Factory instead when each caller genuinely needs a separate asynchronous object.

ARKTELOS

Purpose-built engineering systems for software that has to hold.