import { inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { firstValueFrom, Observable } from 'rxjs';
export function initializeApp_old(appInitService: AppSettingService) {
  return (): Promise<any> => {
    return appInitService.loadAppSetting_p();
  }

};
export function initializeApp() {
   return (): Promise<any> => {
    return inject(AppSettingService).loadAppSetting_p();
  }
  //  return () => inject(AppSettingService).loadAppSetting();
};

@Injectable({ providedIn: 'root' })
export class AppSettingService {
  private _appsetting: any;
  constructor(private http: HttpClient
  ) { }

  public loadAppSetting_p(): Promise<any> {
    const source$ = this.http.get("config/appsetting.json")
    const rs$ = firstValueFrom(source$)
      .then(x => {
        this._appsetting = x;
        console.log("[AppSettingService] assign", x);
      });
    return rs$;
  }
    public loadAppSetting(): Observable<any> {
    const source$ = this.http.get("config/appsetting.json")
   return source$;
  }
  set appSetting(value: any) {
    this._appsetting = value;
  }
  get appSetting(): any {
    return this._appsetting;
  }

}
/* angular 19 new one in app.config.ts
 provideAppInitializer(initializeApp()),
 
/* module put this 
to use it 
in app.module.ts
add
1) 
 providers: [ 
 { provide : APP_INITIALIZER,  multi : true, deps : [AppSettingService], 
      useFactory: initializeApp
    },
  ]

2) 
other this one work too.
providers: [ 
{ 
    provide : APP_INITIALIZER, 
    multi : true, 
     deps : [AppSettingService], 
     useFactory : (appConfigService : AppSettingService) =>  () => appConfigService.loadAppSetting()
}
]

to use it calling something like this
export class TestComponent {
    public test1ServiceUrl: string;

    constructor(public configService: AppConfigService) {
        this.test1ServiceUrl = this.configService.appSetting.test1ServiceUrl;
    }
}
*/