register method

void register(
  1. String id,
  2. dynamic service, [
  3. dynamic arguments = const <dynamic>[]
])

Register a service to the container

The id is the unique identifier of the service and can be used as reference for other services to inject. service can be anything, is service is a function, method or closure, it will be invoked with the arguments within the get call. If a class passed as service the constructor will be called with the arguments and the new object instance will be returned within the get call.

Implementation

void register(String id, dynamic service, [arguments = const <dynamic>[]]) {
  if (has(id)) {
    throw Exception('A service with the id "$id" already exist');
  }

  if (id.trim() == '') {
    throw Exception('The id must have at least one character');
  }

  _services[id] = Service(id, service, arguments);
}