Learn

Getting started

Configure, resolve, and close a small Ark DI container.

v0.1.0-dev.1Beginnerark_di

Getting started

Terminal
shell
dart pub add ark_di
dart
final container = DiContainer.build((binder) {
  binder.bindInstance<AppConfig>(config);
  binder.bindLazySingleton<ApiClient>(
    (resolver) => ApiClient(resolver.get<AppConfig>()),
    dispose: (client) => client.close(),
  );
  binder.bindFactory<CatalogService>(
    (resolver) => CatalogService(resolver.get<ApiClient>()),
  );
});

final service = container.get<CatalogService>();
await container.close();

The configuration callback is one-shot. DiBinder expires when it returns, so runtime code cannot silently mutate registrations. The container owns only the objects whose registration semantics say it does.

ARKTELOS

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