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,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { ApplicationRef, ComponentFactoryResolver, forwardRef, NgModule, Inject } from '@angular/core';
import { ApplicationRef, ComponentFactoryResolver, forwardRef, NgModule, Inject, Type } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
@@ -13,7 +13,7 @@ import { ChartsModule } from 'ng2-charts/ng2-charts';
const BrowserAnimationsModule = (<any>require.__$__nodeRequire('@angular/platform-browser/animations')).BrowserAnimationsModule;
import { IBootstrapService, BOOTSTRAP_SERVICE_ID } from 'sql/services/bootstrap/bootstrapService';
import { IBootstrapParams } from 'sql/services/bootstrap/bootstrapService';
import { Extensions, IInsightRegistry } from 'sql/platform/dashboard/common/insightRegistry';
import { Registry } from 'vs/platform/registry/common/platform';
@@ -41,42 +41,48 @@ let baseComponents = [QueryComponent, ComponentHostDirective, QueryOutputCompone
/* Insights */
let insightComponents = Registry.as<IInsightRegistry>(Extensions.InsightContribution).getAllCtors();
@NgModule({
imports: [
CommonModule,
BrowserModule,
FormsModule,
BrowserAnimationsModule,
ChartsModule,
PanelModule
],
declarations: [
...baseComponents,
...insightComponents,
SlickGrid,
ScrollDirective,
MouseDownDirective,
Checkbox,
SelectBox,
InputBox
],
entryComponents: [
QueryOutputComponent,
...insightComponents
]
})
export class QueryOutputModule {
export const QueryOutputModule = (params: IBootstrapParams, selector: string): Type<any> => {
constructor(
@Inject(forwardRef(() => ComponentFactoryResolver)) private _resolver: ComponentFactoryResolver,
@Inject(BOOTSTRAP_SERVICE_ID) private _bootstrapService: IBootstrapService
) {
@NgModule({
imports: [
CommonModule,
BrowserModule,
FormsModule,
BrowserAnimationsModule,
ChartsModule,
PanelModule
],
declarations: [
...baseComponents,
...insightComponents,
SlickGrid,
ScrollDirective,
MouseDownDirective,
Checkbox,
SelectBox,
InputBox
],
entryComponents: [
QueryOutputComponent,
...insightComponents
],
providers: [
{ provide: IBootstrapParams, useValue: params }
]
})
class ModuleClass {
constructor(
@Inject(forwardRef(() => ComponentFactoryResolver)) private _resolver: ComponentFactoryResolver
) {
}
ngDoBootstrap(appRef: ApplicationRef) {
const factory = this._resolver.resolveComponentFactory(QueryOutputComponent);
(<any>factory).factory.selector = selector;
appRef.bootstrap(factory);
}
}
ngDoBootstrap(appRef: ApplicationRef) {
const factory = this._resolver.resolveComponentFactory(QueryOutputComponent);
const uniqueSelector: string = this._bootstrapService.getUniqueSelector(QUERY_OUTPUT_SELECTOR);
(<any>factory).factory.selector = uniqueSelector;
appRef.bootstrap(factory);
}
}
return ModuleClass;
};