I am facing an issue with a service that is provided in app.module.ts and injected into an exported function within the same module. Despite this setup, when running the code inside MSALInstanceFactory, it is indicating that the service is undefined.
import { HttpClient } from '@angular/common/http';
import { Injectable, Inject } from '@angular/core';
import { Configuration } from '../configuration/configuration';
@Injectable()
export class ConfigurationService {
private configData: Configuration;
constructor(private httpClient: HttpClient) { }
async loadConfigurationData(): Promise<Configuration>{
...
}
}
@NgModule({
declarations: [
AppComponent,
...
],
imports: [
HttpClientModule,
MsalModule,
...
],
providers: [
{
ConfigurationService,
{
provide: APP_INITIALIZER,
useFactory: (configService: ConfigurationService) =>
() => configService.loadConfigurationData(),
deps: [ConfigurationService],
multi: true
},
provide: HTTP_INTERCEPTORS,
useClass: MsalInterceptor,
multi: true
},
{
provide: MSAL_INSTANCE,
useFactory: MSALInstanceFactory
},
{
provide: MSAL_GUARD_CONFIG,
useFactory: MSALGuardConfigFactory
},
{
provide: MSAL_INTERCEPTOR_CONFIG,
useFactory: MSALInterceptorConfigFactory
},
...
],
export function MSALInstanceFactory(configurationService: ConfigurationService): IPublicClientApplication {
return new PublicClientApplication({
auth: {
clientId: configurationService.config.clientId
});
I'm encountering difficulties trying to resolve this issue.
Your assistance in solving this problem would be greatly appreciated.