This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch 
4287-migrate-angular-ui-from-constructor-injection-to-inject
in repository https://gitbox.apache.org/repos/asf/streampipes.git

commit ef67834196ce798d8842f2ddd13b4cf1db5dd0b0
Author: Philipp Zehnder <[email protected]>
AuthorDate: Tue Mar 24 09:48:53 2026 +0100

    migrate app services to inject()
---
 ui/src/app/services/auth.service.ts               | 18 ++++++++++--------
 ui/src/app/services/available-roles.service.ts    |  6 ++++--
 ui/src/app/services/notification-count-service.ts |  6 +++---
 ui/src/app/services/rest-api.service.ts           |  8 +++-----
 ui/src/app/services/secure.pipe.ts                | 10 ++++------
 ui/src/app/services/tour/shepherd.service.ts      | 12 +++++++-----
 6 files changed, 31 insertions(+), 29 deletions(-)

diff --git a/ui/src/app/services/auth.service.ts 
b/ui/src/app/services/auth.service.ts
index eab8325681..f086eebf7d 100644
--- a/ui/src/app/services/auth.service.ts
+++ b/ui/src/app/services/auth.service.ts
@@ -17,7 +17,7 @@
  */
 
 import { RestApi } from './rest-api.service';
-import { Injectable } from '@angular/core';
+import { Injectable, inject } from '@angular/core';
 import { Observable, of, timer } from 'rxjs';
 import { JwtHelperService } from '@auth0/angular-jwt';
 import {
@@ -38,15 +38,17 @@ import {
 
 @Injectable({ providedIn: 'root' })
 export class AuthService {
+    private restApi = inject(RestApi);
+    private tokenStorage = inject(JwtTokenStorageService);
+    private currentUserService = inject(CurrentUserService);
+    private router = inject(Router);
+    private loginService = inject(LoginService);
+
     private refreshInFlight$?: Observable<boolean>;
 
-    constructor(
-        private restApi: RestApi,
-        private tokenStorage: JwtTokenStorageService,
-        private currentUserService: CurrentUserService,
-        private router: Router,
-        private loginService: LoginService,
-    ) {
+    constructor() {
+        const tokenStorage = this.tokenStorage;
+
         if (this.authenticated() && tokenStorage.getUser()) {
             this.currentUserService.authToken$.next(tokenStorage.getToken());
             this.currentUserService.user$.next(tokenStorage.getUser());
diff --git a/ui/src/app/services/available-roles.service.ts 
b/ui/src/app/services/available-roles.service.ts
index f7e1f99424..1dfa3d77c5 100644
--- a/ui/src/app/services/available-roles.service.ts
+++ b/ui/src/app/services/available-roles.service.ts
@@ -16,12 +16,14 @@
  *
  */
 
-import { Injectable } from '@angular/core';
+import { Injectable, inject } from '@angular/core';
 import { Role, RoleService } from '@streampipes/platform-services';
 import { BehaviorSubject, Observable } from 'rxjs';
 
 @Injectable({ providedIn: 'root' })
 export class AvailableRolesService {
+    private roleService = inject(RoleService);
+
     private static readonly ASSET_USER_ROLE = 'ROLE_ASSET_USER';
 
     private availableRolesSubject: BehaviorSubject<Role[]> =
@@ -29,7 +31,7 @@ export class AvailableRolesService {
     public availableRoles$: Observable<Role[]> =
         this.availableRolesSubject.asObservable();
 
-    constructor(private roleService: RoleService) {
+    constructor() {
         this.loadRoles();
     }
 
diff --git a/ui/src/app/services/notification-count-service.ts 
b/ui/src/app/services/notification-count-service.ts
index 7ba1a04817..46dfb60498 100644
--- a/ui/src/app/services/notification-count-service.ts
+++ b/ui/src/app/services/notification-count-service.ts
@@ -15,18 +15,18 @@
  *   limitations under the License.
  */
 
-import { Injectable } from '@angular/core';
+import { Injectable, inject } from '@angular/core';
 import { RestApi } from './rest-api.service';
 import { BehaviorSubject } from 'rxjs';
 
 @Injectable({ providedIn: 'root' })
 export class NotificationCountService {
+    private restApi = inject(RestApi);
+
     public unreadNotificationCount$ = new BehaviorSubject(0);
     lockNotificationId: string;
     lockActive = false;
 
-    constructor(private restApi: RestApi) {}
-
     loadUnreadNotifications() {
         this.restApi.getUnreadNotificationsCount().subscribe(response => {
             this.unreadNotificationCount$.next(response.count);
diff --git a/ui/src/app/services/rest-api.service.ts 
b/ui/src/app/services/rest-api.service.ts
index 4df0f1c33f..6b23228e86 100644
--- a/ui/src/app/services/rest-api.service.ts
+++ b/ui/src/app/services/rest-api.service.ts
@@ -16,7 +16,7 @@
  *
  */
 
-import { Injectable } from '@angular/core';
+import { Injectable, inject } from '@angular/core';
 import { PlatformServicesCommons } from '@streampipes/platform-services';
 import { HttpClient, HttpContext } from '@angular/common/http';
 import { Observable } from 'rxjs';
@@ -24,10 +24,8 @@ import { NGX_LOADING_BAR_IGNORED } from 
'@ngx-loading-bar/http-client';
 
 @Injectable({ providedIn: 'root' })
 export class RestApi {
-    constructor(
-        private platformServicesCommons: PlatformServicesCommons,
-        private $http: HttpClient,
-    ) {}
+    private platformServicesCommons = inject(PlatformServicesCommons);
+    private $http = inject(HttpClient);
 
     getServerUrl() {
         return this.platformServicesCommons.apiBasePath;
diff --git a/ui/src/app/services/secure.pipe.ts 
b/ui/src/app/services/secure.pipe.ts
index fae0b451ee..378d0cb1cb 100644
--- a/ui/src/app/services/secure.pipe.ts
+++ b/ui/src/app/services/secure.pipe.ts
@@ -16,7 +16,7 @@
  *
  */
 
-import { Pipe, PipeTransform } from '@angular/core';
+import { Pipe, PipeTransform, inject } from '@angular/core';
 import { HttpClient } from '@angular/common/http';
 import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
 import { map } from 'rxjs/operators';
@@ -25,11 +25,9 @@ import { CurrentUserService } from '@streampipes/shared-ui';
 
 @Pipe({ name: 'secure' })
 export class SecurePipe implements PipeTransform {
-    constructor(
-        private http: HttpClient,
-        private sanitizer: DomSanitizer,
-        private currentUserService: CurrentUserService,
-    ) {}
+    private http = inject(HttpClient);
+    private sanitizer = inject(DomSanitizer);
+    private currentUserService = inject(CurrentUserService);
 
     transform(url): Observable<SafeUrl> {
         return this.http
diff --git a/ui/src/app/services/tour/shepherd.service.ts 
b/ui/src/app/services/tour/shepherd.service.ts
index bab7b97155..b52c6dd0a7 100644
--- a/ui/src/app/services/tour/shepherd.service.ts
+++ b/ui/src/app/services/tour/shepherd.service.ts
@@ -17,7 +17,7 @@
  */
 
 import Shepherd from 'shepherd.js';
-import { Injectable } from '@angular/core';
+import { Injectable, inject } from '@angular/core';
 import { Router } from '@angular/router';
 import { TourProviderService } from './tour-provider.service';
 import Step from 'shepherd.js/src/types/step';
@@ -26,6 +26,9 @@ import StepOptions = Step.StepOptions;
 
 @Injectable({ providedIn: 'root' })
 export class ShepherdService {
+    private router = inject(Router);
+    private tourProviderService = inject(TourProviderService);
+
     currentTour: Shepherd.Tour;
     currentTourSettings: any;
     timeWaitMillis: number;
@@ -33,10 +36,9 @@ export class ShepherdService {
 
     public tutorialActive$ = new BehaviorSubject(false);
 
-    constructor(
-        private router: Router,
-        private tourProviderService: TourProviderService,
-    ) {
+    constructor() {
+        const tourProviderService = this.tourProviderService;
+
         this.timeWaitMillis = tourProviderService.getTime();
     }
 

Reply via email to