registerFactory<T> method

T Function(Container) registerFactory <T>(
  1. T f(
    1. Container
    ),
  2. {Type as}
)

Registers a factory. Any attempt to resolve the type within this container will return the result of f.

Returns f.

Implementation

T Function(Container) registerFactory<T>(T Function(Container) f, {Type as}) {
  as ??= T;

  if (_factories.containsKey(as)) {
    throw StateError('This container already has a factory for $as.');
  }

  _factories[as] = f;
  return f;
}