ContainerInterface class abstract interface

Interface for a Dependency Injection (DI) container.

This interface defines the contract for a container that manages dependencies in an application. It supports various binding types such as factories, singletons, lazy singletons, and instances. Contextual bindings allow for different resolutions based on a context key, enabling flexible dependency management.

The container provides methods to register dependencies (bind, singleton, etc.), resolve them (resolve, resolveAll), check for existence (has), and manage the container state (unbind, flush).

Example usage:

class MyContainer implements ContainerInterface {
  // Implementation details...
}

Note: Implementations should handle type safety and ensure thread-safety if needed.

Implementers

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

bind<T>(dynamic factory(ContainerInterface), {bool singleton}) → void
Registers a factory function for type T.
bindWhen<T>(String context, dynamic factory(ContainerInterface), {bool singleton = false}) → void
Registers a contextual binding for type T under a specific context.
flush() → void
Flushes all bindings and resets the container to its initial state.
has<T>([String? context]) bool
Checks if a binding exists for type T.
instance<T>(T instance) → void
Registers an existing instance of type T as a singleton.
lazySingleton<T>(dynamic factory(ContainerInterface)) → void
Registers a lazy singleton factory for type T.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolve<T>([String? context]) → T
Resolves and returns an instance of type T.
resolveAll<T>() List<T>
Resolves and returns all instances of type T.
resolveType(Type type, [String? context]) → dynamic
Resolves and returns an instance of the given type.
setMissingBindingHandler(void handler(Type type)) → void
Sets a handler to be called when a service is not found.
singleton<T>(dynamic factory(ContainerInterface)) → void
Registers a singleton factory for type T.
toString() String
A string representation of this object.
inherited
unbind<T>() → void
Removes the binding for type T.

Operators

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