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:
- Local
GetItscope (theprimarycontainer). - 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:
- ModularityInjectableBridge which creates BinderGetIt instances.
Constructors#
BinderGetIt()#
Create a BinderGetIt
wrapping the given primary GetIt instance
and falling back to binder for unresolved lookups.
Implementation
BinderGetIt({required GetIt primary, required contracts.Binder binder})
: _primary = primary,
_binder = binder;
Properties#
allowReassignment read / write#
Implementation
@override
bool get allowReassignment => _primary.allowReassignment;
@override
set allowReassignment(bool value) => _primary.allowReassignment = value;
hashCode no setter inherited#
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
external int get hashCode;
runtimeType no setter inherited#
A representation of the runtime type of the object.
Inherited from Object.
Implementation
external Type get runtimeType;
Methods#
allReady()#
Implementation
@override
Future<void> allReady({
Duration? timeout,
bool ignorePendingAsyncCreation = false,
}) => _primary.allReady(
timeout: timeout,
ignorePendingAsyncCreation: ignorePendingAsyncCreation,
);
allReadySync()#
Implementation
@override
bool allReadySync([bool ignorePendingAsyncCreation = false]) =>
_primary.allReadySync(ignorePendingAsyncCreation);
call()#
Implementation
@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()#
Implementation
@override
T get<T extends Object>({
String? instanceName,
dynamic param1,
dynamic param2,
Type? type,
}) {
// If caller uses GetIt-only features (named registrations / params),
// 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;
// Preserve native GetIt error message for DX.
return _primary.get<T>();
}
getAsync()#
Implementation
@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()#
Implementation
@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()#
Implementation
@override
bool isReadySync<T extends Object>({
Object? instance,
String? instanceName,
}) => _primary.isReadySync<T>(instance: instance, instanceName: instanceName);
isRegistered()#
Implementation
@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#
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:
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:
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
@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()#
Implementation
@override
void registerFactory<T extends Object>(
FactoryFunc<T> factoryFunc, {
String? instanceName,
}) => _primary.registerFactory<T>(factoryFunc, instanceName: instanceName);
registerFactoryParam()#
Implementation
@override
void registerFactoryParam<T extends Object, P1, P2>(
FactoryFuncParam<T, P1, P2> factoryFunc, {
String? instanceName,
}) => _primary.registerFactoryParam<T, P1, P2>(
factoryFunc,
instanceName: instanceName,
);
registerLazySingleton()#
Implementation
@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()#
Implementation
@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()#
Implementation
@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()#
Implementation
@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()#
Implementation
@override
Future<void> reset({bool dispose = true}) => _primary.reset(dispose: dispose);
resetLazySingleton()#
Implementation
@override
FutureOr<void> resetLazySingleton<T extends Object>({
DisposingFunc<T>? disposingFunction,
T? instance,
String? instanceName,
}) => _primary.resetLazySingleton<T>(
disposingFunction: disposingFunction,
instance: instance,
instanceName: instanceName,
);
signalReady()#
Implementation
@override
void signalReady(Object? instance) => _primary.signalReady(instance);
toString() override#
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
@override
String toString() => _primary.toString();
unregister()#
Implementation
@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#
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 == omust be true.-
Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false. -
Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must 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
external bool operator ==(Object other);