APP_INITIALIZER migration breaks with `useFactory` and dependencies. · Issue #58788 · angular/angular · GitHub
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions