Skip to content
This repository was archived by the owner on Sep 16, 2022. It is now read-only.

Document and refactor root-level services #1179

Open
3 tasks
matanlurey opened this issue Apr 3, 2018 · 0 comments
Open
3 tasks

Document and refactor root-level services #1179

matanlurey opened this issue Apr 3, 2018 · 0 comments

Comments

@matanlurey
Copy link
Contributor

As part of the runApp migration, I ran into the following issues:

  • You could never override services in bootstrapFactory (missing feature)
  • To be able to override services, I add to add a hacky "middle" injector (internal):
/// **INTERNAL ONLY**: Creates a new application-level Injector.
///
/// This is more complicated than just creating a new Injector, because we want
/// to make sure we allow [userProvidedInjector] to override _some_ top-level
/// services (`APP_ID`, `ExceptionHandler`) _and_ to ensure that Angular-level
/// services (`ApplicationRef`) get the user-provided versions.
Injector _appInjector(InjectorFactory userProvidedInjector) {
  // These are the required root services.
  final minimalInjector = minimalApp(platformInjector());

  // These are the user-provided overrides.
  final userInjector = userProvidedInjector(minimalInjector);

  // Get a handle of NgZone, so we can create ApplicationRef in it.
  final NgZone ngZone = unsafeCast(minimalInjector.get(NgZone));

  // ... and then we add ApplicationRef, which has the unique property of
  // injecting services (specifically, `ExceptionHandler` and `APP_ID`) that
  // might have come from the user-provided injector, instead of the minimal.
  //
  // We also add other top-level services with similar constraints:
  // * `AppViewUtils`
  return ngZone.run(() {
    return new Injector.map({
      ApplicationRef: new ApplicationRefImpl(
        unsafeCast(minimalInjector.get(PlatformRef)),
        ngZone,
        userInjector,
      ),
      AppViewUtils: new AppViewUtils(
        unsafeCast(userInjector.get(APP_ID)),
        unsafeCast(minimalInjector.get(SanitizationService)),
        unsafeCast(minimalInjector.get(EventManager)),
      ),
    }, userInjector);
  });
}

... which led me to the following:

  • We should document what root-level services are provided by AngularDart
  • We should document what can be overridden and what cannot
    • AFAIK, only ExceptionHandler and APP_ID are really safe for overriding
  • We should consider removing the root-level injector entirely, making DI pseudo optional

The reason I say pseudo optional is that likely we will still need to provide some services, likely through an Injector.map, like above, so others can inject them in DI, but we don't need to use DI ourselves in order to create the root-level services.

matanlurey added a commit that referenced this issue Apr 4, 2018
... now with `Testability` working again, and other bug fixes.

Work towards #914.

Closes #1048
Closes #1174.

Filed #1175.
Filed #1179.

PiperOrigin-RevId: 191628083
matanlurey added a commit that referenced this issue Apr 4, 2018
... now with `Testability` working again, and other bug fixes.

Work towards #914.

Closes #1048
Closes #1174.

Filed #1175.
Filed #1179.

PiperOrigin-RevId: 191628083
matanlurey added a commit that referenced this issue Apr 4, 2018
... now with `Testability` working again, and other bug fixes.

Work towards #914.

Closes #1048
Closes #1174.

Filed #1175.
Filed #1179.

PiperOrigin-RevId: 191628083
michilu pushed a commit to michilu/scaffold that referenced this issue Apr 13, 2018
... now with `Testability` working again, and other bug fixes.

Work towards angulardart/angular#914.

Closes angulardart/angular#1048
Closes angulardart/angular#1174.

Filed angulardart/angular#1175.
Filed angulardart/angular#1179.

PiperOrigin-RevId: 191628083
@matanlurey matanlurey added this to the D milestone Oct 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant