getInstanceFromCacheAsync<KInstance extends BaseKoreInstance, InputState> method
Future<KInstance>
getInstanceFromCacheAsync<
KInstance extends BaseKoreInstance, InputState>( - String id, {
- dynamic params,
- int? index,
- String? scopeId,
- bool withoutConnections = false,
})
Implementation
Future<KInstance>
getInstanceFromCacheAsync<KInstance extends BaseKoreInstance, InputState>(
String id, {
dynamic params,
int? index,
String? scopeId,
bool withoutConnections = false,
}) async {
final scope = scopeId ?? BaseScopes.global;
if (!container.contains(scope, id, index)) {
performCheckForCyclicDependencies(id, index);
final instance = await constructAndInitializeInstanceAsync<KInstance>(
id,
params: params,
);
container.addObjectInScope(
object: instance,
type: id,
scopeId: scope,
);
finishBuildingInstance(id, index);
return instance;
}
final instance = container.getObjectInScope(
type: id,
scopeId: scope,
index: index ?? 0,
) as KInstance;
if (!instance.isInitialized) {
if (withoutConnections) {
instance.initializeWithoutConnections(params);
await instance.initializeWithoutConnectionsAsync();
} else {
instance.initialize(params);
await instance.initializeAsync();
}
}
return instance;
}