Skip to content

APP_INITIALIZER migration breaks with useFactory and dependencies. #58788

Description

@JeanMeche

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

The Provide initializer schematic transforms

      import { APP_INITIALIZER } from '@angular/core';

      const providers = [{
        provide: APP_INITIALIZER,
        useFactory: (a: ServiceA, b: ServiceB) => {
          return () => a.init();
        },
        deps: [ServiceA, ServiceB],
        multi: true,
      }];

to:

const providers = [
  provideAppInitializer(
    ((a: ServiceA, b: ServiceB) => {
      return () => a.init();
    })(inject(ServiceA), inject(ServiceB))
  ),
];

But a provider definition is not a valid injection context.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions