register<TService, TImplementation extends TService> method

void register<TService, TImplementation extends TService>(
  1. Constructor<TImplementation> constructor, [
  2. Lifestyle lifestyle = Lifestyle.transient
])

Registers a constructor for type TService. This constructor must be specified in constructor and must generate an instance of TImplementation which, in turn, must inherit from TService. Default value of lifestyle is Lifestyle.transient.

Implementation

void register<TService, TImplementation extends TService>(
    Constructor<TImplementation> constructor,
    [Lifestyle lifestyle = Lifestyle.transient]) {
  Requires.isNotAnAmbiguousType(TService, 'TService');

  if (options.notAllowOverridingRegistrations &&
      _producers.containsKey(TService)) {
    throw TypeAlreadyRegisteredException(TService);
  }

  var instanceProducer = lifestyle
      .createInstanceProducer<TService, TImplementation>(constructor);

  addInstanceProducer(TService, instanceProducer);
}