unregisterInstance<T> method

void unregisterInstance<T>({
  1. String scope = BaseScopes.global,
  2. int? index,
})

Unregisters instance in scope and resets object reference counter in scope

index - index for this instance scope - string scope to get instance from

Implementation

void unregisterInstance<T>({
  String scope = BaseScopes.global,
  int? index,
}) {
  if (scope == BaseScopes.global) {
    container.removeObjectInScope(
      type: T.toString(),
      scopeId: scope,
      index: index,
      onRemove: (instance) => instance.dispose(),
    );
  } else {
    container
      ..removeObjectInScope(
        type: T.toString(),
        scopeId: scope,
        index: index,
        onRemove: (instance) => instance.dispose(),
      )
      ..removeObjectReferenceInScope(
        type: T,
        scopeId: scope,
        index: index,
      );
  }
}