dartian_di 1.1.0 copy "dartian_di: ^1.1.0" to clipboard
dartian_di: ^1.1.0 copied to clipboard

Dependency injection container for Dartian with auto-discovery annotations and cycle detection

dartian_di #

Dependency injection container for Dartian with auto-discovery annotations and cycle detection.

Features #

  • Service container powered by get_it
  • Auto-discovery annotations: @Singleton, @Service, @LazySingleton
  • Named dependencies with @Named
  • Module support with @Module and @Provides
  • Circular dependency detection
  • Code generation support

Installation #

dependencies:
  dartian_di: ^1.0.0

Usage #

Basic Registration #

import 'package:dartian_di/dartian_di.dart';

final container = DIContainer();

// Singleton (one instance)
container.registerSingleton<DatabaseService>(() => DatabaseService());

// Factory (new instance each time)
container.registerFactory<RequestHandler>(() => RequestHandler());

// Lazy singleton (created on first access)
container.registerLazySingleton<CacheService>(() => CacheService());

// Get services
final db = container.get<DatabaseService>();

Annotations for Auto-Discovery #

@Singleton()
class DatabaseService { }

@Service()
class UserRepository { }

@LazySingleton()
class ExpensiveService { }

@Singleton(name: 'primary')
class PrimaryDatabase { }

Cycle Detection #

// Detect circular dependencies at registration time
container.registerSingletonWithDeps<ServiceA>(
  () => ServiceA(),
  dependsOn: [ServiceB], // Will throw if B depends on A
);

Part of Dartian #

This package is part of the Dartian framework.

License #

AGPL-3.0 - See LICENSE for details.

0
likes
130
points
73
downloads

Publisher

verified publisherdartian.org

Weekly Downloads

Dependency injection container for Dartian with auto-discovery annotations and cycle detection

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#dependency-injection #di #ioc #service-locator

Documentation

API reference

License

unknown (license)

Dependencies

analyzer, build, get_it, source_gen

More

Packages that depend on dartian_di