ngbracket / ngbracket/ngx-layout

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

Open
#115 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
235
Forks
16
Avg merge
17m
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read core/base/base2.ts and core/public-api.ts, then inspect the 23 directives and the core, flex, extended, grid, and server entry points before running the Angular inject schematic. Done means reconciling every super() call, deciding and documenting compatibility for the public abstract base, and keeping the full 468-test suite green.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
api, frontend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.