registerAsType method

void registerAsType(
  1. dynamic locator,
  2. dynamic type
)

Registers a component using its type (a constructor function).

  • locator a locator to identify component to be created.
  • type a component type.

Implementation

void registerAsType(locator, type) {
  if (locator == null) throw Exception('Locator cannot be null');
  if (type == null) throw Exception('Factory cannot be null');
  _registrations.add(Registration(locator, (locator) {
    try {
      return TypeReflector.createInstanceByType(type, []);
    } catch (ex) {
      return null;
    }
  }));
}