Injector class

A simple dependency injection container. Provides type-safe registration and retrieval of instances.

Constructors

Injector.new()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

registeredTypes List<Type>
Gets all registered types.
no setter

Static Methods

get<T>({String? name}) → T
Gets an instance of the given type. Throws StateError if the type is not registered.
isRegistered<T>({String? name}) bool
Checks if a type is registered.
put<T>(T instance, {String? name}) → void
Registers an instance for the given type.
putProvider<T>(BaseProvider<T> provider) → void
Registers a provider for the given type.
remove<T>({String? name}) → void
Removes an instance or provider for the given type.
reset() → void
Clears all registered instances and providers.
tryGet<T>({String? name}) → T?
Gets an instance if it exists, otherwise returns null.