Skip to content

Commit 661153b

Browse files
authored
refactor(*): migrate DI from constructors to inject() API (#16075)
1 parent ace116f commit 661153b

File tree

276 files changed

+2625
-3854
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

276 files changed

+2625
-3854
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ All notable changes for each version of this project will be documented in this
6363
6464
### Breaking Changes
6565

66+
#### Dependency Injection Refactor
67+
- All internal DI now uses the `inject()` API across `igniteui-angular` (no more constructor DI in library code).
68+
- If you extend our components/services or call their constructors directly, remove DI params and switch to `inject()` (e.g., `protected foo = inject(FooService);`).
69+
- App usage via templates remains the same; no action needed unless you subclass/override our types.
70+
6671
#### Multiple Entry Points Support
6772

6873
The library now supports multiple entry points for better tree-shaking and code splitting. While the main entry point (`igniteui-angular`) remains fully backwards compatible by re-exporting all granular entry points, we recommend migrating to the new entry points for optimal bundle sizes.

projects/igniteui-angular-elements/src/analyzer/elements.config.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export var registerConfig = [
4646
IgxRowIslandComponent,
4747
],
4848
contentQueries: [],
49-
additionalProperties: [],
49+
additionalProperties: [{ name: "cdr", writable: true }],
5050
methods: ["show", "hide"],
5151
boolProps: ["hidden"],
5252
provideAs: IgxActionStripToken,
@@ -65,6 +65,7 @@ export var registerConfig = [
6565
],
6666
contentQueries: [],
6767
additionalProperties: [
68+
{ name: "grid", writable: true },
6869
{ name: "selected", writable: true },
6970
{ name: "index" },
7071
{ name: "visibleIndex" },
@@ -75,7 +76,6 @@ export var registerConfig = [
7576
{ name: "level" },
7677
{ name: "filteringExpressionsTree" },
7778
{ name: "parent", writable: true },
78-
{ name: "grid", writable: true },
7979
{ name: "topLevelParent" },
8080
],
8181
methods: ["pin", "unpin", "move", "autosize"],
@@ -130,13 +130,13 @@ export var registerConfig = [
130130
{ name: "childColumns" },
131131
{ name: "columnGroup" },
132132
{ name: "columnLayout" },
133+
{ name: "grid", writable: true },
133134
{ name: "index" },
134135
{ name: "visibleIndex" },
135136
{ name: "columnLayoutChild" },
136137
{ name: "level" },
137138
{ name: "filteringExpressionsTree" },
138139
{ name: "parent", writable: true },
139-
{ name: "grid", writable: true },
140140
{ name: "topLevelParent" },
141141
],
142142
methods: ["pin", "unpin", "move", "autosize"],
@@ -187,12 +187,12 @@ export var registerConfig = [
187187
{ name: "selected", writable: true },
188188
{ name: "childColumns" },
189189
{ name: "columnGroup" },
190+
{ name: "grid", writable: true },
190191
{ name: "index" },
191192
{ name: "columnLayoutChild" },
192193
{ name: "level" },
193194
{ name: "filteringExpressionsTree" },
194195
{ name: "parent", writable: true },
195-
{ name: "grid", writable: true },
196196
{ name: "topLevelParent" },
197197
],
198198
methods: ["pin", "unpin", "move", "autosize"],
@@ -252,6 +252,10 @@ export var registerConfig = [
252252
additionalProperties: [
253253
{ name: "groupsRecords" },
254254
{ name: "selectedCells" },
255+
{ name: "validation" },
256+
{ name: "gridAPI" },
257+
{ name: "cdr" },
258+
{ name: "navigation", writable: true },
255259
{ name: "shouldGenerate", writable: true },
256260
{ name: "rowList" },
257261
{ name: "dataRowList" },
@@ -261,10 +265,6 @@ export var registerConfig = [
261265
{ name: "lastSearchInfo" },
262266
{ name: "filteredData" },
263267
{ name: "filteredSortedData" },
264-
{ name: "validation" },
265-
{ name: "gridAPI" },
266-
{ name: "cdr" },
267-
{ name: "navigation", writable: true },
268268
{ name: "virtualizationState" },
269269
{ name: "nativeElement" },
270270
{ name: "defaultRowHeight" },
@@ -550,6 +550,8 @@ export var registerConfig = [
550550
{ name: "selectedCells" },
551551
{ name: "gridAPI", writable: true },
552552
{ name: "navigation", writable: true },
553+
{ name: "validation" },
554+
{ name: "cdr" },
553555
{ name: "shouldGenerate", writable: true },
554556
{ name: "rowList" },
555557
{ name: "dataRowList" },
@@ -559,8 +561,6 @@ export var registerConfig = [
559561
{ name: "lastSearchInfo" },
560562
{ name: "filteredData" },
561563
{ name: "filteredSortedData" },
562-
{ name: "validation" },
563-
{ name: "cdr" },
564564
{ name: "virtualizationState" },
565565
{ name: "nativeElement" },
566566
{ name: "defaultRowHeight" },
@@ -733,17 +733,17 @@ export var registerConfig = [
733733
},
734734
],
735735
additionalProperties: [
736-
{ name: "dimensionsSortingExpressions" },
736+
{ name: "gridAPI" },
737737
{ name: "navigation", writable: true },
738+
{ name: "dimensionsSortingExpressions" },
738739
{ name: "allDimensions" },
740+
{ name: "validation" },
741+
{ name: "cdr" },
739742
{ name: "rowList" },
740743
{ name: "dataRowList" },
741744
{ name: "lastSearchInfo" },
742745
{ name: "filteredData" },
743746
{ name: "filteredSortedData" },
744-
{ name: "validation" },
745-
{ name: "gridAPI" },
746-
{ name: "cdr" },
747747
{ name: "virtualizationState" },
748748
{ name: "nativeElement" },
749749
{ name: "defaultRowHeight" },
@@ -865,12 +865,12 @@ export var registerConfig = [
865865
{ name: "rowIslandAPI", writable: true },
866866
{ name: "gridAPI", writable: true },
867867
{ name: "navigation", writable: true },
868+
{ name: "validation" },
869+
{ name: "cdr" },
868870
{ name: "shouldGenerate", writable: true },
869871
{ name: "rowList" },
870872
{ name: "dataRowList" },
871873
{ name: "transactions" },
872-
{ name: "validation" },
873-
{ name: "cdr" },
874874
{ name: "nativeElement" },
875875
{ name: "defaultRowHeight" },
876876
{ name: "columns" },
@@ -1009,6 +1009,10 @@ export var registerConfig = [
10091009
{ name: "processedRootRecords", writable: true },
10101010
{ name: "processedRecords", writable: true },
10111011
{ name: "selectedCells" },
1012+
{ name: "validation" },
1013+
{ name: "gridAPI" },
1014+
{ name: "cdr" },
1015+
{ name: "navigation", writable: true },
10121016
{ name: "shouldGenerate", writable: true },
10131017
{ name: "rowList" },
10141018
{ name: "dataRowList" },
@@ -1017,10 +1021,6 @@ export var registerConfig = [
10171021
{ name: "lastSearchInfo" },
10181022
{ name: "filteredData" },
10191023
{ name: "filteredSortedData" },
1020-
{ name: "validation" },
1021-
{ name: "gridAPI" },
1022-
{ name: "cdr" },
1023-
{ name: "navigation", writable: true },
10241024
{ name: "virtualizationState" },
10251025
{ name: "nativeElement" },
10261026
{ name: "defaultRowHeight" },

projects/igniteui-angular-elements/src/app/wrapper/wrapper.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectorRef, Component, QueryList, TemplateRef, ViewChildren } from '@angular/core';
1+
import { ChangeDetectorRef, Component, QueryList, TemplateRef, ViewChildren, inject } from '@angular/core';
22
import { Subject } from 'rxjs';
33
import { TemplateRefWrapper } from './template-ref-wrapper';
44

@@ -13,6 +13,8 @@ type TemplateFunction = (arg: any) => TemplateResult;
1313
imports: []
1414
})
1515
export class TemplateWrapperComponent {
16+
private cdr = inject(ChangeDetectorRef);
17+
1618

1719
public templateFunctions: TemplateFunction[] = [];
1820
public templateRendered = new Subject<HTMLElement>();
@@ -25,8 +27,6 @@ export class TemplateWrapperComponent {
2527
*/
2628
@ViewChildren(TemplateRef)
2729
public templateRefs: QueryList<TemplateRef<any>>;
28-
29-
constructor(private cdr: ChangeDetectorRef) { }
3030

3131
protected litRender(container: HTMLElement, templateFunc: (arg: any) => TemplateResult, arg: any) {
3232
const part = render(templateFunc(arg), container);

projects/igniteui-angular-elements/src/lib/icon.broadcast.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable, Optional } from '@angular/core';
1+
import { Injectable, inject } from '@angular/core';
22
import { PlatformUtil } from 'igniteui-angular/core';
33
import { IconMeta, IgxIconService } from 'igniteui-angular/icon';
44

@@ -25,12 +25,12 @@ export interface BroadcastIconsChangeMessage {
2525
/** @hidden @internal **/
2626
@Injectable()
2727
export class IgxIconBroadcastService {
28+
protected _iconService = inject(IgxIconService);
29+
private _platformUtil = inject(PlatformUtil, { optional: true });
30+
2831
private iconBroadcastChannel: BroadcastChannel | null;
2932

30-
constructor(
31-
protected _iconService: IgxIconService,
32-
@Optional() private _platformUtil: PlatformUtil
33-
) {
33+
constructor() {
3434
if (this._platformUtil?.isBrowser) {
3535
this.create();
3636

projects/igniteui-angular-elements/src/lib/state.component.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, EnvironmentInjector, EventEmitter, Inject, Injector, Output, ViewContainerRef } from '@angular/core';
1+
import { Component, EventEmitter, Output, inject } from '@angular/core';
22
import { IFilteringExpressionsTree, IGroupingState, IPagingState, ISortingExpression } from 'igniteui-angular/core';
33
import { GridFeatures, GridSelectionRange, GridType, IColumnState, IGridStateCollection, IGX_GRID_BASE, IgxGridStateBaseDirective, IPinningConfig, IPivotConfiguration } from 'igniteui-angular/grids/core';
44

@@ -44,15 +44,7 @@ export interface IGridStateInfo {
4444
standalone: true
4545
})
4646
export class IgxGridStateComponent extends IgxGridStateBaseDirective {
47-
48-
constructor(
49-
@Inject(IGX_GRID_BASE) grid: GridType,
50-
protected override viewRef: ViewContainerRef, protected override envInjector: EnvironmentInjector,
51-
protected override injector: Injector,
52-
) {
53-
super(grid, viewRef, envInjector, injector);
54-
}
55-
47+
public override grid = inject<GridType>(IGX_GRID_BASE);
5648
/**
5749
* Restores grid features' state based on the IGridStateInfo object passed as an argument.
5850
* @param state object to restore state from.

projects/igniteui-angular/accordion/src/accordion/accordion.component.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
AfterContentInit, AfterViewInit, ChangeDetectorRef, Component, ContentChildren, EventEmitter,
3-
HostBinding, Input, OnDestroy, Output, QueryList, booleanAttribute
4-
} from '@angular/core';
1+
import { AfterContentInit, AfterViewInit, ChangeDetectorRef, Component, ContentChildren, EventEmitter, HostBinding, Input, OnDestroy, Output, QueryList, booleanAttribute, inject } from '@angular/core';
52
import { fromEvent, Subject } from 'rxjs';
63
import { takeUntil } from 'rxjs/operators';
74
import { ACCORDION_NAVIGATION_KEYS } from 'igniteui-angular/core';
@@ -57,6 +54,8 @@ let NEXT_ID = 0;
5754
standalone: true
5855
})
5956
export class IgxAccordionComponent implements AfterContentInit, AfterViewInit, OnDestroy {
57+
private cdr = inject(ChangeDetectorRef);
58+
6059
/**
6160
* Get/Set the `id` of the accordion component.
6261
* Default value is `"igx-accordion-0"`;
@@ -218,8 +217,6 @@ export class IgxAccordionComponent implements AfterContentInit, AfterViewInit, O
218217
private _enabledPanels!: IgxExpansionPanelComponent[];
219218
private _singleBranchExpand = false;
220219

221-
constructor(private cdr: ChangeDetectorRef) { }
222-
223220
/** @hidden @internal **/
224221
public ngAfterContentInit(): void {
225222
this.updatePanelsAnimation();

projects/igniteui-angular/action-strip/src/action-strip/action-strip.component.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
AfterViewInit,
1414
ElementRef,
1515
booleanAttribute,
16-
AfterContentInit
16+
AfterContentInit,
17+
inject
1718
} from '@angular/core';
1819

1920

@@ -31,7 +32,7 @@ import { IgxDropDownComponent, IgxDropDownItemComponent, IgxDropDownItemNavigati
3132
standalone: true
3233
})
3334
export class IgxActionStripMenuItemDirective {
34-
constructor(public templateRef: TemplateRef<any>) {}
35+
public templateRef = inject<TemplateRef<any>>(TemplateRef);
3536
}
3637

3738
/* blazorElement */
@@ -82,6 +83,11 @@ export class IgxActionStripMenuItemDirective {
8283
providers: [{ provide: IgxActionStripToken, useExisting: IgxActionStripComponent }]
8384
})
8485
export class IgxActionStripComponent implements IgxActionStripToken, AfterViewInit, AfterContentInit {
86+
private _viewContainer = inject(ViewContainerRef);
87+
private renderer = inject(Renderer2);
88+
protected el = inject(ElementRef);
89+
public cdr = inject(ChangeDetectorRef);
90+
8591

8692
/* blazorSuppress */
8793
/**
@@ -186,14 +192,6 @@ export class IgxActionStripComponent implements IgxActionStripToken, AfterViewIn
186192
private _resourceStrings = getCurrentResourceStrings(ActionStripResourceStringsEN);
187193
private _originalParent!: HTMLElement;
188194

189-
constructor(
190-
private _viewContainer: ViewContainerRef,
191-
private renderer: Renderer2,
192-
protected el: ElementRef,
193-
/** @hidden @internal **/
194-
public cdr: ChangeDetectorRef,
195-
) { }
196-
197195
/**
198196
* Menu Items list.
199197
*

projects/igniteui-angular/avatar/src/avatar/avatar.component.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import { NgTemplateOutlet } from '@angular/common';
2-
import {
3-
Component,
4-
ElementRef,
5-
HostBinding,
6-
Input,
7-
OnInit,
8-
TemplateRef,
9-
ViewChild
10-
} from '@angular/core';
2+
import { Component, ElementRef, HostBinding, Input, OnInit, TemplateRef, ViewChild, inject } from '@angular/core';
113

124
import { normalizeURI } from 'igniteui-angular/core';
135
import { IgxIconComponent } from 'igniteui-angular/icon';
@@ -56,6 +48,8 @@ export type IgxAvatarType = (typeof IgxAvatarType)[keyof typeof IgxAvatarType];
5648
imports: [IgxIconComponent, NgTemplateOutlet]
5749
})
5850
export class IgxAvatarComponent implements OnInit {
51+
public elementRef = inject(ElementRef);
52+
5953
/**
6054
* Returns the `aria-label` attribute of the avatar.
6155
*
@@ -332,8 +326,6 @@ export class IgxAvatarComponent implements OnInit {
332326
}
333327
}
334328

335-
constructor(public elementRef: ElementRef) { }
336-
337329
/**
338330
* Returns the css url of the image.
339331
*

projects/igniteui-angular/banner/src/banner/banner.component.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
import {
2-
Component,
3-
ContentChild,
4-
ElementRef,
5-
EventEmitter,
6-
HostBinding,
7-
Input,
8-
Output,
9-
ViewChild
10-
} from '@angular/core';
1+
import { Component, ContentChild, ElementRef, EventEmitter, HostBinding, Input, Output, ViewChild, inject } from '@angular/core';
112

123
import { IgxIconComponent } from 'igniteui-angular/icon';
134
import { IgxButtonDirective, IgxRippleDirective } from 'igniteui-angular/directives';
@@ -52,6 +43,8 @@ export interface BannerCancelEventArgs extends BannerEventArgs, CancelableEventA
5243
imports: [IgxExpansionPanelComponent, IgxExpansionPanelBodyComponent, IgxButtonDirective, IgxRippleDirective]
5344
})
5445
export class IgxBannerComponent implements IToggleView {
46+
public elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
47+
5548
/**
5649
* @hidden
5750
*/
@@ -238,8 +231,6 @@ export class IgxBannerComponent implements IToggleView {
238231
private _animationSettings: ToggleAnimationSettings;
239232
private _resourceStrings = getCurrentResourceStrings(BannerResourceStringsEN);
240233

241-
constructor(public elementRef: ElementRef<HTMLElement>) { }
242-
243234
/**
244235
* Opens the banner
245236
*

0 commit comments

Comments
 (0)