Angular Individual Service Injection - Decouple bootstrap service (#1457)

* change services to be individually injected into angular

* messing around with injection

* change angular bootstrapping to factory style

* formatting

* formatting

* fix imports

* fix build errors

* fix testsw

* fix tests

* fix compile errors
This commit is contained in:
Anthony Dresser
2018-05-23 16:51:02 -07:00
committed by GitHub
parent cd0f9b71c5
commit 1359354387
68 changed files with 1011 additions and 1116 deletions

View File

@@ -4,15 +4,17 @@
*--------------------------------------------------------------------------------------------*/
import { Routes, RouterModule } from '@angular/router';
import { ApplicationRef, ComponentFactoryResolver, ModuleWithProviders, NgModule,
Inject, forwardRef } from '@angular/core';
import {
ApplicationRef, ComponentFactoryResolver, ModuleWithProviders, NgModule,
Inject, forwardRef, Type
} from '@angular/core';
import { APP_BASE_HREF, CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { IBootstrapService, BOOTSTRAP_SERVICE_ID } from 'sql/services/bootstrap/bootstrapService';
import { TaskDialogComponent, TASKDIALOG_SELECTOR } from 'sql/parts/tasks/dialog/taskDialog.component';
import { CreateDatabaseComponent } from 'sql/parts/admin/database/create/createDatabase.component';
import { IBootstrapParams } from 'sql/services/bootstrap/bootstrapService';
// Setup routes for various child components
const appRoutes: Routes = [
@@ -25,33 +27,37 @@ const appRoutes: Routes = [
{ path: '**', component: CreateDatabaseComponent }
];
export const TaskDialogModule = (params: IBootstrapParams, selector: string): Type<any> => {
@NgModule({
declarations: [
TaskDialogComponent,
CreateDatabaseComponent
],
entryComponents: [TaskDialogComponent],
imports: [
FormsModule,
CommonModule,
BrowserModule,
<ModuleWithProviders>RouterModule.forRoot(appRoutes)
],
providers: [
{ provide: APP_BASE_HREF, useValue: '/' },
{ provide: IBootstrapParams, useValue: params }
]
})
class ModuleClass {
@NgModule({
declarations: [
TaskDialogComponent,
CreateDatabaseComponent
],
entryComponents: [TaskDialogComponent],
imports: [
FormsModule,
CommonModule,
BrowserModule,
<ModuleWithProviders>RouterModule.forRoot(appRoutes)
],
providers: [{ provide: APP_BASE_HREF, useValue: '/' }]
})
export class TaskDialogModule {
constructor(
@Inject(forwardRef(() => ComponentFactoryResolver)) private _resolver: ComponentFactoryResolver
) {
}
constructor(
@Inject(forwardRef(() => ComponentFactoryResolver)) private _resolver: ComponentFactoryResolver,
@Inject(BOOTSTRAP_SERVICE_ID) private _bootstrapService: IBootstrapService
) {
ngDoBootstrap(appRef: ApplicationRef) {
const factory = this._resolver.resolveComponentFactory(TaskDialogComponent);
(<any>factory).factory.selector = selector;
appRef.bootstrap(factory);
}
}
ngDoBootstrap(appRef: ApplicationRef) {
const factory = this._resolver.resolveComponentFactory(TaskDialogComponent);
const uniqueSelector: string = this._bootstrapService.getUniqueSelector(TASKDIALOG_SELECTOR);
(<any>factory).factory.selector = uniqueSelector;
appRef.bootstrap(factory);
}
}
return ModuleClass;
};