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}) {
  Type t2 = T;
  if (as != null) {
    t2 = as;
  }

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

  _factories[t2] = f;
  return f;
}