registerType<T> method

void registerType<T>(
  1. [Function factoryMethod]
)

Registers a type that can be resolved.

The typeCreationFunction is a reference to a function that should create an instance of this type.

Implementation

void registerType<T>([Function factoryMethod]) {
  ArgumentError.checkNotNull(factoryMethod, "factoryMethod");

  if (_dependencyRegistrations
      .any((r) => identical(r.typeRegistered, Utilities.typeOf<T>()))) {
    throw StateError("The same type cannot be registered twice");
  }
  _dependencyRegistrations.add(_DependencyRegistration(
      _RegistrationType.typeRegistration, Utilities.typeOf<T>(),
      factoryMethod: factoryMethod));
}