I'm working on a Angular Electron application where we display loading screen while the application is starting up. This means we have to do couple of BE requests and only remove the loader when we receive desired answers. We only read data in those calls, there are no write calls there.
Everything works but the INITIALIZER keeps growing in complexity and gains more and more deps with every request from Product Owner. This it's current state:
// app-init.ts
export function initApp(
healthService: HealthService, // Spring health - retryWithBackOff to handle BE not running
sseService: SseService, // Opens SSE channel
clientService: ClientService, // Project specific
resultService: ResultsService, // Project specific
loggerService: LoggerService, // self explanatory
messageService: MessageService // helps to propagate status messages to loader screen
): () => Promise<any> {
// ...
}
// app.module.ts
{
provide: APP_INITIALIZER,
useFactory: initApp,
multi: true,
deps: [HealthService, SseService, ClientService, ResultsService, LoggerService, MessageService],
},
My questions is, wouldn't it be better to create one use only service, to execute initial requests within the APP_INITIALIZER? I know this goes against the DRY principle but I see a benefit here. Plus all our services and models are generated from API, we just run an npm command to update them. This should keep the good pretty stable.
It would look like this:
// app-init.ts
export function initApp(
initService: InitService, // Would group Health + Project specific services
sseService: SseService, // Opens SSE channel
loggerService: LoggerService, // self explanatory
messageService: MessageService // helps to propagate status messages to loader screen
): () => Promise<any> {
// ...
}
// app.module.ts
{
provide: APP_INITIALIZER,
useFactory: initApp,
multi: true,
deps: [InitService, SseService, LoggerService, MessageService],
},
If the need for a new Project Specific service call would arise, we would just add it to InitService. This would prevent INITIALIZER deps from growing although it would introduce duplicity of some calls.
Is it a good idea? Or is there a better way I'm not aware of?