From 519d99f1d4f391de5d9d0d2d0f9864508db99c4d Mon Sep 17 00:00:00 2001 From: Fahri Gedik Date: Tue, 8 Jul 2025 10:17:35 +0300 Subject: [PATCH] refactor: migrate account package to inject() DI --- .../src/lib/proxy/account/account.service.ts | 6 +++--- .../src/lib/proxy/account/profile.service.ts | 6 +++--- .../account/controllers/account.service.ts | 6 +++--- .../src/lib/auth-wrapper.service.ts | 13 +++++++------ .../account-core/src/lib/tenant-box.service.ts | 14 ++++++-------- .../change-password.component.ts | 16 +++++++--------- .../forgot-password.component.ts | 10 +++++----- .../manage-profile/manage-profile.component.ts | 10 ++++------ .../personal-settings-half-row.component.ts | 8 ++++++-- .../components/register/register.component.ts | 18 ++++++++---------- .../reset-password/reset-password.component.ts | 16 +++++++--------- 11 files changed, 59 insertions(+), 64 deletions(-) diff --git a/npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/account.service.ts b/npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/account.service.ts index adeb2ee5c9..ad584495c6 100644 --- a/npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/account.service.ts +++ b/npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/account.service.ts @@ -1,12 +1,14 @@ import type { RegisterDto, ResetPasswordDto, SendPasswordResetCodeDto } from './models'; import { RestService } from '@abp/ng.core'; -import { Injectable } from '@angular/core'; +import { Injectable, inject } from '@angular/core'; import type { IdentityUserDto } from '../identity/models'; @Injectable({ providedIn: 'root', }) export class AccountService { + private restService = inject(RestService); + apiName = 'AbpAccount'; register = (input: RegisterDto) => @@ -32,6 +34,4 @@ export class AccountService { body: input, }, { apiName: this.apiName }); - - constructor(private restService: RestService) {} } diff --git a/npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/profile.service.ts b/npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/profile.service.ts index 0cea6b8cfb..a14c6cedfd 100644 --- a/npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/profile.service.ts +++ b/npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/profile.service.ts @@ -1,11 +1,13 @@ import type { ChangePasswordInput, ProfileDto, UpdateProfileDto } from './models'; import { RestService } from '@abp/ng.core'; -import { Injectable } from '@angular/core'; +import { Injectable, inject } from '@angular/core'; @Injectable({ providedIn: 'root', }) export class ProfileService { + private restService = inject(RestService); + apiName = 'AbpAccount'; changePassword = (input: ChangePasswordInput) => @@ -30,6 +32,4 @@ export class ProfileService { body: input, }, { apiName: this.apiName }); - - constructor(private restService: RestService) {} } diff --git a/npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/web/areas/account/controllers/account.service.ts b/npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/web/areas/account/controllers/account.service.ts index 8adf5385b0..52c779655b 100644 --- a/npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/web/areas/account/controllers/account.service.ts +++ b/npm/ng-packs/packages/account-core/proxy/src/lib/proxy/account/web/areas/account/controllers/account.service.ts @@ -1,11 +1,13 @@ import type { AbpLoginResult, UserLoginInfo } from './models/models'; import { RestService } from '@abp/ng.core'; -import { Injectable } from '@angular/core'; +import { Injectable, inject } from '@angular/core'; @Injectable({ providedIn: 'root', }) export class AccountService { + private restService = inject(RestService); + apiName = 'AbpAccount'; checkPasswordByLogin = (login: UserLoginInfo) => @@ -30,6 +32,4 @@ export class AccountService { url: '/api/account/logout', }, { apiName: this.apiName }); - - constructor(private restService: RestService) {} } diff --git a/npm/ng-packs/packages/account-core/src/lib/auth-wrapper.service.ts b/npm/ng-packs/packages/account-core/src/lib/auth-wrapper.service.ts index 7bad8ef96a..10ca25380b 100644 --- a/npm/ng-packs/packages/account-core/src/lib/auth-wrapper.service.ts +++ b/npm/ng-packs/packages/account-core/src/lib/auth-wrapper.service.ts @@ -1,4 +1,4 @@ -import { Injectable, Injector } from '@angular/core'; +import { Injectable, Injector, inject } from '@angular/core'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { ActivatedRoute } from '@angular/router'; @@ -6,6 +6,9 @@ import { ConfigStateService, MultiTenancyService } from '@abp/ng.core'; @Injectable() export class AuthWrapperService { + readonly multiTenancy = inject(MultiTenancyService); + private configState = inject(ConfigStateService); + isMultiTenancyEnabled$ = this.configState.getDeep$('multiTenancy.isEnabled'); get enableLocalLogin$(): Observable { @@ -25,11 +28,9 @@ export class AuthWrapperService { return this.isTenantBoxVisibleForCurrentRoute && this.multiTenancy.isTenantBoxVisible; } - constructor( - public readonly multiTenancy: MultiTenancyService, - private configState: ConfigStateService, - injector: Injector, - ) { + constructor() { + const injector = inject(Injector); + this.route = injector.get(ActivatedRoute); } diff --git a/npm/ng-packs/packages/account-core/src/lib/tenant-box.service.ts b/npm/ng-packs/packages/account-core/src/lib/tenant-box.service.ts index bcb37c3d48..2890d90776 100644 --- a/npm/ng-packs/packages/account-core/src/lib/tenant-box.service.ts +++ b/npm/ng-packs/packages/account-core/src/lib/tenant-box.service.ts @@ -5,11 +5,16 @@ import { SessionStateService, } from '@abp/ng.core'; import { ToasterService } from '@abp/ng.theme.shared'; -import { Injectable } from '@angular/core'; +import { Injectable, inject } from '@angular/core'; import { finalize } from 'rxjs/operators'; @Injectable() export class TenantBoxService { + private toasterService = inject(ToasterService); + private tenantService = inject(AbpTenantService); + private sessionState = inject(SessionStateService); + private configState = inject(ConfigStateService); + currentTenant$ = this.sessionState.getTenant$(); name?: string; @@ -18,13 +23,6 @@ export class TenantBoxService { modalBusy!: boolean; - constructor( - private toasterService: ToasterService, - private tenantService: AbpTenantService, - private sessionState: SessionStateService, - private configState: ConfigStateService, - ) {} - onSwitch() { const tenant = this.sessionState.getTenant(); this.name = tenant?.name || ''; diff --git a/npm/ng-packs/packages/account/src/lib/components/change-password/change-password.component.ts b/npm/ng-packs/packages/account/src/lib/components/change-password/change-password.component.ts index 9e1ae788f0..ad5db820ac 100644 --- a/npm/ng-packs/packages/account/src/lib/components/change-password/change-password.component.ts +++ b/npm/ng-packs/packages/account/src/lib/components/change-password/change-password.component.ts @@ -1,6 +1,6 @@ import { ProfileService } from '@abp/ng.account.core/proxy'; import { ButtonComponent, getPasswordValidators, ToasterService } from '@abp/ng.theme.shared'; -import { Component, Injector, OnInit } from '@angular/core'; +import { Component, Injector, OnInit, inject } from '@angular/core'; import { ReactiveFormsModule, UntypedFormBuilder, @@ -32,6 +32,12 @@ const PASSWORD_FIELDS = ['newPassword', 'repeatNewPassword']; export class ChangePasswordComponent implements OnInit, Account.ChangePasswordComponentInputs, Account.ChangePasswordComponentOutputs { + private fb = inject(UntypedFormBuilder); + private injector = inject(Injector); + private toasterService = inject(ToasterService); + private profileService = inject(ProfileService); + private manageProfileState = inject(ManageProfileStateService); + form!: UntypedFormGroup; inProgress?: boolean; @@ -44,14 +50,6 @@ export class ChangePasswordComponent return errors.concat(groupErrors.filter(({ key }) => key === 'passwordMismatch')); }; - constructor( - private fb: UntypedFormBuilder, - private injector: Injector, - private toasterService: ToasterService, - private profileService: ProfileService, - private manageProfileState: ManageProfileStateService, - ) {} - ngOnInit(): void { this.hideCurrentPassword = !this.manageProfileState.getProfile()?.hasPassword; diff --git a/npm/ng-packs/packages/account/src/lib/components/forgot-password/forgot-password.component.ts b/npm/ng-packs/packages/account/src/lib/components/forgot-password/forgot-password.component.ts index 815c95d71c..873d45c243 100644 --- a/npm/ng-packs/packages/account/src/lib/components/forgot-password/forgot-password.component.ts +++ b/npm/ng-packs/packages/account/src/lib/components/forgot-password/forgot-password.component.ts @@ -1,5 +1,5 @@ import { AccountService } from '@abp/ng.account.core/proxy'; -import { Component } from '@angular/core'; +import { Component, inject } from '@angular/core'; import { ReactiveFormsModule, UntypedFormBuilder, @@ -24,16 +24,16 @@ import { NgxValidateCoreModule } from '@ngx-validate/core'; ], }) export class ForgotPasswordComponent { + private fb = inject(UntypedFormBuilder); + private accountService = inject(AccountService); + form: UntypedFormGroup; inProgress?: boolean; isEmailSent = false; - constructor( - private fb: UntypedFormBuilder, - private accountService: AccountService, - ) { + constructor() { this.form = this.fb.group({ email: ['', [Validators.required, Validators.email]], }); diff --git a/npm/ng-packs/packages/account/src/lib/components/manage-profile/manage-profile.component.ts b/npm/ng-packs/packages/account/src/lib/components/manage-profile/manage-profile.component.ts index 797bb9f492..d7e8c8b98d 100644 --- a/npm/ng-packs/packages/account/src/lib/components/manage-profile/manage-profile.component.ts +++ b/npm/ng-packs/packages/account/src/lib/components/manage-profile/manage-profile.component.ts @@ -1,7 +1,7 @@ import { ProfileService } from '@abp/ng.account.core/proxy'; import { fadeIn, LoadingDirective } from '@abp/ng.theme.shared'; import { transition, trigger, useAnimation } from '@angular/animations'; -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, inject } from '@angular/core'; import { eAccountComponents } from '../../enums/components'; import { ManageProfileStateService } from '../../services/manage-profile.state.service'; import { CommonModule } from '@angular/common'; @@ -33,6 +33,9 @@ import { ChangePasswordComponent } from '../change-password/change-password.comp ], }) export class ManageProfileComponent implements OnInit { + protected profileService = inject(ProfileService); + protected manageProfileState = inject(ManageProfileStateService); + selectedTab = 0; changePasswordKey = eAccountComponents.ChangePassword; @@ -43,11 +46,6 @@ export class ManageProfileComponent implements OnInit { hideChangePasswordTab?: boolean; - constructor( - protected profileService: ProfileService, - protected manageProfileState: ManageProfileStateService, - ) {} - ngOnInit() { this.profileService.get().subscribe(profile => { this.manageProfileState.setProfile(profile); diff --git a/npm/ng-packs/packages/account/src/lib/components/personal-settings/personal-settings-half-row.component.ts b/npm/ng-packs/packages/account/src/lib/components/personal-settings/personal-settings-half-row.component.ts index ac99a51c23..be6287e954 100644 --- a/npm/ng-packs/packages/account/src/lib/components/personal-settings/personal-settings-half-row.component.ts +++ b/npm/ng-packs/packages/account/src/lib/components/personal-settings/personal-settings-half-row.component.ts @@ -1,4 +1,4 @@ -import { Component, Inject } from '@angular/core'; +import { Component, inject } from '@angular/core'; import { EXTENSIONS_FORM_PROP, FormProp, @@ -24,12 +24,16 @@ import { LocalizationPipe } from '@abp/ng.core'; imports: [ReactiveFormsModule, LocalizationPipe], }) export class PersonalSettingsHalfRowComponent { + private propData = inject(EXTENSIONS_FORM_PROP); + public displayName: string; public name: string; public id: string; public formGroup!: UntypedFormGroup; - constructor(@Inject(EXTENSIONS_FORM_PROP) private propData: FormProp) { + constructor() { + const propData = this.propData; + this.displayName = propData.displayName; this.name = propData.name; this.id = propData.id || ''; diff --git a/npm/ng-packs/packages/account/src/lib/components/register/register.component.ts b/npm/ng-packs/packages/account/src/lib/components/register/register.component.ts index 18b4935c92..93bbfe26f4 100644 --- a/npm/ng-packs/packages/account/src/lib/components/register/register.component.ts +++ b/npm/ng-packs/packages/account/src/lib/components/register/register.component.ts @@ -6,7 +6,7 @@ import { LocalizationPipe, } from '@abp/ng.core'; import { ButtonComponent, getPasswordValidators, ToasterService } from '@abp/ng.theme.shared'; -import { Component, Injector, OnInit } from '@angular/core'; +import { Component, Injector, OnInit, inject } from '@angular/core'; import { ReactiveFormsModule, UntypedFormBuilder, @@ -35,6 +35,13 @@ const { maxLength, required, email } = Validators; ], }) export class RegisterComponent implements OnInit { + protected fb = inject(UntypedFormBuilder); + protected accountService = inject(AccountService); + protected configState = inject(ConfigStateService); + protected toasterService = inject(ToasterService); + protected authService = inject(AuthService); + protected injector = inject(Injector); + form!: UntypedFormGroup; inProgress?: boolean; @@ -43,15 +50,6 @@ export class RegisterComponent implements OnInit { authWrapperKey = eAccountComponents.AuthWrapper; - constructor( - protected fb: UntypedFormBuilder, - protected accountService: AccountService, - protected configState: ConfigStateService, - protected toasterService: ToasterService, - protected authService: AuthService, - protected injector: Injector, - ) {} - ngOnInit() { this.init(); this.buildForm(); diff --git a/npm/ng-packs/packages/account/src/lib/components/reset-password/reset-password.component.ts b/npm/ng-packs/packages/account/src/lib/components/reset-password/reset-password.component.ts index d04a99ae98..1e8d043000 100644 --- a/npm/ng-packs/packages/account/src/lib/components/reset-password/reset-password.component.ts +++ b/npm/ng-packs/packages/account/src/lib/components/reset-password/reset-password.component.ts @@ -1,6 +1,6 @@ import { AccountService } from '@abp/ng.account.core/proxy'; import { ButtonComponent, getPasswordValidators } from '@abp/ng.theme.shared'; -import { Component, Injector, OnInit } from '@angular/core'; +import { Component, Injector, OnInit, inject } from '@angular/core'; import { ReactiveFormsModule, UntypedFormBuilder, @@ -26,6 +26,12 @@ const PASSWORD_FIELDS = ['password', 'confirmPassword']; ], }) export class ResetPasswordComponent implements OnInit { + private fb = inject(UntypedFormBuilder); + private accountService = inject(AccountService); + private route = inject(ActivatedRoute); + private router = inject(Router); + private injector = inject(Injector); + form!: UntypedFormGroup; inProgress = false; @@ -38,14 +44,6 @@ export class ResetPasswordComponent implements OnInit { return errors.concat(groupErrors.filter(({ key }) => key === 'passwordMismatch')); }; - constructor( - private fb: UntypedFormBuilder, - private accountService: AccountService, - private route: ActivatedRoute, - private router: Router, - private injector: Injector, - ) {} - ngOnInit(): void { this.route.queryParams.subscribe(({ userId, resetToken }) => { if (!userId || !resetToken) this.router.navigateByUrl('/account/login');