I want to avoid having to import every service into all my Angular 4 components, so I created something like this
import * as UtilityService from '../../services/utility.service';
Instead of doing this
import { AppStateService, InternalStateType } from '../services/appstate.service';
import { Logging } from '../services/utility.service';
import { AuthenticationService } from '../services/authentication.service';
import { DataService } from '../services/data.service';
import { Utils } from '../services/utility.service';
import { RouteProtectionService } from '../services/route-protection.service';
import { UrlManagementService } from '../services/url-managing.service';
So now I can accesss all the classes from any component by referencing UtilityService.Classname
i.e. UtilityService.AppState
, UtilityService.Authentication
, etc.
constructor(
public appState: UtilityService.AppState,
public utilities: UtilityService.Utils,
public dataService: UtilityService.Data,
private appInsightsService: UtilityService.AppInsights,
private titleService: UtilityService.Titles) {
}
Then inside utility.service.ts, I have this
export { AppState, InternalStateType } from './appstate.service';
export { Authentication } from './authentication.service';
export { Data } from './data.service';
export { RouteProtection } from './route-protection.service';
export { UrlManagement } from './url-managing.service';
export { AppInsightsService } from '@markpieszak/ng-application-insights';
export { Title } from '@angular/platform-browser';
It compiles fine in typescript, but when running the app, angular complains
Error: Can't resolve all parameters for Authentication: ([object Object], [object Object], ?, ?, ?).
I already specified the provider for each of them in the AppModule, and it works when I import the classes normally. So why can't I import a barrel of classes and use them in Angular dependency injection?