Created
June 20, 2019 06:46
-
-
Save buildmotion/af96118f3627f83b7f81d7ce72fc30b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgModule, APP_INITIALIZER, ErrorHandler } from "@angular/core"; | |
import { CommonModule } from "@angular/common"; | |
import { | |
LoggingService, | |
LoggingModule, | |
LogglyWriter | |
} from "@angularlicious/logging"; | |
import { | |
ConfigurationService, | |
ConfigurationModule | |
} from "@angularlicious/configuration"; | |
import { ConsoleWriter } from "@angularlicious/logging"; | |
import { | |
ErrorHandlingModule, | |
ErrorHandlingService | |
} from "@angularlicious/error-handling"; | |
import { environment } from "./../../../environments/environment"; | |
/** | |
* The factory function to initialize the logging service and writer for the | |
* application. | |
* | |
* @param loggingService | |
* @param consoleWriter | |
*/ | |
export function initializeLogWriter(consoleWriter: ConsoleWriter) { | |
console.log(`Initializing [Console Writer] from [AppModule]`); | |
return () => { | |
return consoleWriter; | |
}; | |
} | |
@NgModule({ | |
declarations: [], | |
imports: [ | |
CommonModule, | |
ErrorHandlingModule, | |
LoggingModule, | |
ConfigurationModule.forRoot({ config: environment.appConfig }) | |
], | |
providers: [ | |
ConfigurationService, | |
LoggingService, | |
ConsoleWriter, | |
LogglyWriter, | |
{ | |
provide: ErrorHandler, | |
useClass: ErrorHandlingService | |
}, | |
{ | |
provide: APP_INITIALIZER, | |
useFactory: initializeLogWriter, | |
deps: [LoggingService, ConsoleWriter, LogglyWriter], | |
multi: true | |
}, | |
{ | |
provide: ErrorHandler, | |
useClass: ErrorHandlingService, | |
deps: [ConfigurationService, LoggingService] | |
} | |
] | |
}) | |
export class LibraryInitializerModule {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment