Skip to content
binder_get_itClassesBinderGetIt

BinderGetIt

class BinderGetIt

GetIt wrapper that falls back to Modularity's Binder chain on resolve.

This is the integration layer between injectable-generated factories and the Modularity DI system. When injectable factories call getIt.get<T>(), this wrapper resolves through:

  1. Local GetIt scope (the primary container).
  2. Modularity Binder chain (imports -> parent).

This allows injectable-registered types to depend on types from imported or parent modules without explicit cross-registration.

Named registrations (instanceName) and factory params are delegated to the underlying GetIt only, as the Modularity Binder interface does not support those concepts.

See also:

Constructors

BinderGetIt()

BinderGetIt({required dynamic primary, required dynamic binder})

Create a BinderGetIt wrapping the given primary GetIt instance and falling back to binder for unresolved lookups.

Implementation
dart
BinderGetIt({required GetIt primary, required contracts.Binder binder})
  : _primary = primary,
    _binder = binder;

Properties

allowReassignment read / write

bool get allowReassignment
Implementation
dart
@override
bool get allowReassignment => _primary.allowReassignment;

@override
set allowReassignment(bool value) => _primary.allowReassignment = value;

hashCode no setter inherited

int get hashCode

The hash code for this object.

A hash code is a single integer which represents the state of the object that affects operator == comparisons.

All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).

If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.

Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.

Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.

If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.

Inherited from Object.

Implementation
dart
external int get hashCode;

runtimeType no setter inherited

Type get runtimeType

A representation of the runtime type of the object.

Inherited from Object.

Implementation
dart
external Type get runtimeType;

Methods

allReady()

Future<void> allReady({Duration? timeout, bool ignorePendingAsyncCreation = false})
Implementation
dart
@override
Future<void> allReady({
  Duration? timeout,
  bool ignorePendingAsyncCreation = false,
}) => _primary.allReady(
  timeout: timeout,
  ignorePendingAsyncCreation: ignorePendingAsyncCreation,
);

allReadySync()

bool allReadySync([bool ignorePendingAsyncCreation = false])
Implementation
dart
@override
bool allReadySync([bool ignorePendingAsyncCreation = false]) =>
    _primary.allReadySync(ignorePendingAsyncCreation);

call()

T call<T extends Object>({String? instanceName, dynamic param1, dynamic param2, Type? type})
Implementation
dart
@override
T call<T extends Object>({
  String? instanceName,
  dynamic param1,
  dynamic param2,
  Type? type,
}) => get<T>(
  instanceName: instanceName,
  param1: param1,
  param2: param2,
  type: type,
);

get()

T get<T extends Object>({String? instanceName, dynamic param1, dynamic param2, Type? type})
Implementation
dart
@override
T get<T extends Object>({
  String? instanceName,
  dynamic param1,
  dynamic param2,
  Type? type,
}) {
  &#47;&#47; If caller uses GetIt-only features (named registrations &#47; params),
  &#47;&#47; delegate without trying Binder fallbacks.
  final usesAdvancedGetItFeatures =
      instanceName != null ||
      param1 != null ||
      param2 != null ||
      type != null;
  if (usesAdvancedGetItFeatures) {
    return _primary.get<T>(
      instanceName: instanceName,
      param1: param1,
      param2: param2,
      type: type,
    );
  }

  if (_primary.isRegistered<T>()) {
    return _primary.get<T>();
  }

  final resolved = _binder.tryGet<T>();
  if (resolved != null) return resolved;

  &#47;&#47; Preserve native GetIt error message for DX.
  return _primary.get<T>();
}

getAsync()

Future<T> getAsync<T extends Object>({String? instanceName, dynamic param1, dynamic param2, Type? type})
Implementation
dart
@override
Future<T> getAsync<T extends Object>({
  String? instanceName,
  dynamic param1,
  dynamic param2,
  Type? type,
}) async {
  final usesAdvancedGetItFeatures =
      instanceName != null ||
      param1 != null ||
      param2 != null ||
      type != null;
  if (usesAdvancedGetItFeatures) {
    return _primary.getAsync<T>(
      instanceName: instanceName,
      param1: param1,
      param2: param2,
      type: type,
    );
  }

  if (_primary.isRegistered<T>()) {
    return _primary.getAsync<T>();
  }

  final resolved = _binder.tryGet<T>();
  if (resolved != null) return resolved;

  return _primary.getAsync<T>();
}

isReady()

Future<void> isReady<T extends Object>({Object? instance, String? instanceName, Duration? timeout, Object? callee})
Implementation
dart
@override
Future<void> isReady<T extends Object>({
  Object? instance,
  String? instanceName,
  Duration? timeout,
  Object? callee,
}) => _primary.isReady<T>(
  instance: instance,
  instanceName: instanceName,
  timeout: timeout,
  callee: callee,
);

isReadySync()

bool isReadySync<T extends Object>({Object? instance, String? instanceName})
Implementation
dart
@override
bool isReadySync<T extends Object>({
  Object? instance,
  String? instanceName,
}) => _primary.isReadySync<T>(instance: instance, instanceName: instanceName);

isRegistered()

bool isRegistered<T extends Object>({Object? instance, String? instanceName, Type? type})
Implementation
dart
@override
bool isRegistered<T extends Object>({
  Object? instance,
  String? instanceName,
  Type? type,
}) {
  if (instanceName != null || instance != null || type != null) {
    return _primary.isRegistered<T>(
      instance: instance,
      instanceName: instanceName,
      type: type,
    );
  }
  if (_primary.isRegistered<T>()) return true;
  return _binder.contains(T);
}

noSuchMethod() override

dynamic noSuchMethod(Invocation invocation)

Invoked when a nonexistent method or property is accessed.

A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:

dart
dynamic object = 1;
object.add(42); // Statically allowed, run-time error

This invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).

Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.

A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:

dart
class MockList<T> implements List<T> {
  noSuchMethod(Invocation invocation) {
    log(invocation);
    super.noSuchMethod(invocation); // Will throw.
  }
}
void main() {
  MockList().add(42);
}

This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.

If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.

The default behavior is to throw a NoSuchMethodError.

Implementation
dart
@override
dynamic noSuchMethod(Invocation invocation) {
  throw UnsupportedError(
    'BinderGetIt does not support ${invocation.memberName}. '
    'Only the subset of GetIt API used by injectable is implemented.',
  );
}

registerFactory()

void registerFactory<T extends Object>(dynamic factoryFunc, {String? instanceName})
Implementation
dart
@override
void registerFactory<T extends Object>(
  FactoryFunc<T> factoryFunc, {
  String? instanceName,
}) => _primary.registerFactory<T>(factoryFunc, instanceName: instanceName);

registerFactoryParam()

void registerFactoryParam<T extends Object, P1, P2>(dynamic factoryFunc, {String? instanceName})
Implementation
dart
@override
void registerFactoryParam<T extends Object, P1, P2>(
  FactoryFuncParam<T, P1, P2> factoryFunc, {
  String? instanceName,
}) => _primary.registerFactoryParam<T, P1, P2>(
  factoryFunc,
  instanceName: instanceName,
);

registerLazySingleton()

void registerLazySingleton<T extends Object>(dynamic factoryFunc, {dynamic dispose, String? instanceName, (void Function(T))? onCreated, bool useWeakReference = false})
Implementation
dart
@override
void registerLazySingleton<T extends Object>(
  FactoryFunc<T> factoryFunc, {
  DisposingFunc<T>? dispose,
  String? instanceName,
  void Function(T)? onCreated,
  bool useWeakReference = false,
}) => _primary.registerLazySingleton<T>(
  factoryFunc,
  dispose: dispose,
  instanceName: instanceName,
  onCreated: onCreated,
  useWeakReference: useWeakReference,
);

registerSingleton()

T registerSingleton<T extends Object>(T instance, {dynamic dispose, String? instanceName, bool? signalsReady})
Implementation
dart
@override
T registerSingleton<T extends Object>(
  T instance, {
  DisposingFunc<T>? dispose,
  String? instanceName,
  bool? signalsReady,
}) => _primary.registerSingleton<T>(
  instance,
  dispose: dispose,
  instanceName: instanceName,
  signalsReady: signalsReady ?? false,
);

registerSingletonAsync()

void registerSingletonAsync<T extends Object>(dynamic factoryFunc, {String? instanceName, Iterable<Type>? dependsOn, dynamic dispose, (void Function(T))? onCreated, bool? signalsReady})
Implementation
dart
@override
void registerSingletonAsync<T extends Object>(
  FactoryFuncAsync<T> factoryFunc, {
  String? instanceName,
  Iterable<Type>? dependsOn,
  DisposingFunc<T>? dispose,
  void Function(T)? onCreated,
  bool? signalsReady,
}) => _primary.registerSingletonAsync<T>(
  factoryFunc,
  instanceName: instanceName,
  dependsOn: dependsOn,
  dispose: dispose,
  onCreated: onCreated,
  signalsReady: signalsReady ?? false,
);

registerSingletonWithDependencies()

void registerSingletonWithDependencies<T extends Object>(dynamic factoryFunc, {String? instanceName, required Iterable<Type>? dependsOn, dynamic dispose, bool? signalsReady})
Implementation
dart
@override
void registerSingletonWithDependencies<T extends Object>(
  FactoryFunc<T> factoryFunc, {
  String? instanceName,
  required Iterable<Type>? dependsOn,
  DisposingFunc<T>? dispose,
  bool? signalsReady,
}) => _primary.registerSingletonWithDependencies<T>(
  factoryFunc,
  instanceName: instanceName,
  dependsOn: dependsOn,
  dispose: dispose,
  signalsReady: signalsReady ?? false,
);

reset()

Future<void> reset({bool dispose = true})
Implementation
dart
@override
Future<void> reset({bool dispose = true}) => _primary.reset(dispose: dispose);

resetLazySingleton()

FutureOr<void> resetLazySingleton<T extends Object>({dynamic disposingFunction, T? instance, String? instanceName})
Implementation
dart
@override
FutureOr<void> resetLazySingleton<T extends Object>({
  DisposingFunc<T>? disposingFunction,
  T? instance,
  String? instanceName,
}) => _primary.resetLazySingleton<T>(
  disposingFunction: disposingFunction,
  instance: instance,
  instanceName: instanceName,
);

signalReady()

void signalReady(Object? instance)
Implementation
dart
@override
void signalReady(Object? instance) => _primary.signalReady(instance);

toString() override

String toString()

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Implementation
dart
@override
String toString() => _primary.toString();

unregister()

FutureOr<void> unregister<T extends Object>({Object? instance, String? instanceName, dynamic disposingFunction, bool ignoreReferenceCount = false})
Implementation
dart
@override
FutureOr<void> unregister<T extends Object>({
  Object? instance,
  String? instanceName,
  DisposingFunc<T>? disposingFunction,
  bool ignoreReferenceCount = false,
}) => _primary.unregister<T>(
  instance: instance,
  instanceName: instanceName,
  disposingFunction: disposingFunction,
  ignoreReferenceCount: ignoreReferenceCount,
);

Operators

operator ==() inherited

bool operator ==(Object other)

The equality operator.

The default behavior for all Objects is to return true if and only if this object and other are the same object.

Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:

  • Total: It must return a boolean for all arguments. It should never throw.

  • Reflexive: For all objects o, o == o must be true.

  • Symmetric: For all objects o1 and o2, o1 == o2 and o2 == o1 must either both be true, or both be false.

  • Transitive: For all objects o1, o2, and o3, if o1 == o2 and o2 == o3 are true, then o1 == o3 must be true.

The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.

If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.

Inherited from Object.

Implementation
dart
external bool operator ==(Object other);