registerBind<T> method

void registerBind<T>(
  1. Bind<T> bind
)

Implementation

void registerBind<T>(Bind<T> bind) {
  final objectKey = _getKey(bind.type, bind.name);

  if (!_factories.containsKey(objectKey)) {
    logger.debug(
        'Registering ${bind.isSingleton ? 'singleton' : 'factory'}  $objectKey');
    _factories[objectKey] = bind;
  } else if (bind.replaceIfExists) {
    logger.info(
        'Replacing ${bind.isSingleton ? 'singleton' : 'factory'} $objectKey to new object');
    _factories[objectKey] = bind;
  } else {
    final objectKey2 = objectKey;
    final message =
        'Object $objectKey2 is already defined!, consider use named bind to register the same type.';
    logger.error(message);
    throw StarkException(message);
  }
}