register<T extends Object> method
Registers a dependency instance of type T.
name can be used to distinguish between multiple instances of the same type.
session can be used to group dependencies that should be cleared together.
Implementation
void register<T extends Object>(final T instance, {final String? name, final String? session}) {
if (T.toString() == 'Object') {
throw WeaverException('T is Object. Cannot register object of the exact type of "Object"');
}
log('Registering object of type $T');
final dependencyKey = DependencyKey(type: T, name: name);
if (isRegistered<T>() && !allowReassignment) {
throw WeaverException(
'Cannot register object of $dependencyKey because there is an instance already registered',
);
}
if (_dependencyMap.containsKey(dependencyKey)) {
final dependency = (_dependencyMap.find(dependencyKey)! as Dependency<T>);
dependency.value = instance;
} else {
_dependencyMap.set(dependencyKey, Dependency<T>.value(instance), session: session);
}
notifyObservers();
}