put<T> static method
Registers a singleton instance in the dependency store.
If a dependency with the same type and tag already exists, it will be overwritten with a warning logged.
Parameters:
dependency: The instance to registertag: Optional identifier for multiple instances of the same typefenix: Iftrue, the dependency will auto-recreate after deletion
Returns the registered instance.
Example:
final controller = Dependency.put(MyController());
// With tag
Dependency.put(AuthService(), tag: 'primary');
// Phoenix mode - auto-recreates
Dependency.put(CacheService(), fenix: true);
Implementation
static T put<T>(
T dependency, {
String? tag,
bool fenix = false,
}) {
final key = _getKey(dependency.runtimeType, tag: tag);
if (_dependencyStore[key] != null) {
Logger.warn(
'Dependency of type ${dependency.runtimeType} is being overwritten',
tag: 'Dependency',
);
}
_dependencyStore[key] = dependency;
if (fenix) {
_lazyBuilders[key] = () => dependency;
}
return _dependencyStore[key];
}