Skip to content

Adopt inject() over constructor DI (deferred until after 22.0.0) #115

Description

@DuncanFaulkner

Summary

Migrate the library from constructor parameter injection to the inject() function, using Angular's schematic:

ng generate @angular/core:inject

This is deferred until after the 22.0.0 release — it's a purely internal/stylistic refactor with no consumer-facing behavior change, and folding it into the release would mix a large mechanical refactor with functional changes.

Scope in this codebase

  • 23 directives extend the abstract BaseDirective2, each calling super(elRef, styleBuilder, styler, marshal).
  • 32 @Inject(TOKEN) sites across 5 secondary entry points: core, flex, extended, grid, server.
  • BaseDirective2 (core/base/base2.ts) has a protected constructor with parameter-property deps and is exported from the public API (core/public-api.ts), so it's a consumer extension point.

Risks / caveats (why this needs care, not fire-and-forget)

  1. Inheritance + super(...) — when the base drops constructor params, all 23 super(...) calls must change in lockstep. The schematic can leave a partial migration across entry points that needs manual cleanup.
  2. BaseDirective2 is public + abstract — removing its constructor params is a breaking change for any downstream app that subclasses it and calls super(...). If migrating it, run the schematic in backwards-compatibility mode so a compatible protected constructor is retained (or treat it as an intentional, documented breaking change for the next major).

Acceptance

  • Run ng generate @angular/core:inject in a dedicated PR (not the release PR)
  • Manually reconcile the BaseDirective2 hierarchy / super() calls
  • Decide & document the public abstract base handling (backwards-compat vs. breaking)
  • Full test suite green (currently 468 tests) to confirm no behavior change

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions