resolveStaticAndCreate static method

  1. @experimental
ReflectiveInjector resolveStaticAndCreate(
  1. List<Object> providersOrLists, [
  2. Injector? parent
])

Creates a new Injector that resolves some Provider instances.

In particular, only the following provider types are now valid:

  • ValueProvider (or Provider(useValue: ...))
  • ExistingProvider (or Provider(useExisting: ...))
  • FactoryProvider (or Provider(useFactory: ...)) with deps provided.

Specifically, any providers that require looking up factory functions or argument information for factory functions at runtime are not supported since they would defeat the tree-shaking improvements of "runApp".

See https://github.com/angulardart/angular/issues/1426 for details.

Any other type of Provider will throw during creation in development mode and may fail unexpectedly in production mode. This is to allow eased migration towards the runApp API without entirely giving up the ability to use the dynamic nature of ReflectiveInjector.

WARNING: This is not intended to be a long-term API, and instead is an alternative to ReflectiveInjector.resolveAndCreate. It is greatly preferred to use Injector.map or @GeneratedInjector for new usages.

Implementation

@experimental
static ReflectiveInjector resolveStaticAndCreate(
  List<Object> providersOrLists, [
  Injector? parent,
]) {
  final flatProviders = _flattenProviders(providersOrLists);
  if (isDevMode) {
    _assertStaticProviders(flatProviders.providers.values);
    _assertStaticProviders(flatProviders.multiProviders);
    _assertGlobalSingletonService(flatProviders.providers.values);
    _assertGlobalSingletonService(flatProviders.multiProviders);
  }
  return _RuntimeInjector(
    flatProviders.providers,
    flatProviders.multiProviders,
    parent,
    true,
  );
}