delete<S> method
Delete registered Class Instance S (or tag) and, closes any open
controllers DisposableInterface, cleans up the memory
/// Deletes the Instance<S>, cleaning the memory.
Deletes the Instance<S>, cleaning the memory and closes any open
controllers (DisposableInterface).
tagOptional "tag" used to register the InstancekeyFor internal usage, is the processed key used to register the Instance. don't use it unless you know what you are doing.forceWill delete an Instance even if marked aspermanent.
Implementation
// ///
// /// - [tag] Optional "tag" used to register the Instance
// /// - [key] For internal usage, is the processed key used to register
// /// the Instance. **don't use** it unless you know what you are doing.
/// Deletes the Instance<[S]>, cleaning the memory and closes any open
/// controllers (`DisposableInterface`).
///
/// - [tag] Optional "tag" used to register the Instance
/// - [key] For internal usage, is the processed key used to register
/// the Instance. **don't use** it unless you know what you are doing.
/// - [force] Will delete an Instance even if marked as `permanent`.
bool delete<S>({String? tag, String? key, bool force = false}) {
final newKey = key ?? _getKey(S, tag);
if (!_singl.containsKey(newKey)) {
Flower.log('Instance "$newKey" already removed.', tag: "Error");
return false;
}
final dep = _singl[newKey];
if (dep == null) return false;
final _InstanceBuilderFactory builder;
if (dep.isDirty) {
builder = dep.lateRemove ?? dep;
} else {
builder = dep;
}
if (builder.permanent && !force) {
Flower.log(
// ignore: lines_longer_than_80_chars
'"$newKey" has been marked as permanent, SmartManagement is not authorized to delete it.',
tag: "Error",
);
return false;
}
final i = builder.dependency;
if (i is FlowerServiceMixin && !force) {
return false;
}
if (i is LifeCycleMixin) {
i.onDelete();
Flower.log('"$newKey" onDelete() called');
}
if (builder.fenix) {
builder.dependency = null;
builder.isInit = false;
return true;
} else {
if (dep.lateRemove != null) {
dep.lateRemove = null;
Flower.log('"$newKey" deleted from memory');
return false;
} else {
_singl.remove(newKey);
if (_singl.containsKey(newKey)) {
Flower.log('Error removing object "$newKey"', tag: "Error");
} else {
Flower.log('"$newKey" deleted from memory');
}
return true;
}
}
}