mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
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:
@@ -3,11 +3,11 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IBootstrapService, BOOTSTRAP_SERVICE_ID } from 'sql/services/bootstrap/bootstrapService';
|
||||
import { ConnectionManagementInfo } from 'sql/parts/connection/common/connectionManagementInfo';
|
||||
import { ITaskDialogComponent } from 'sql/parts/tasks/common/tasks';
|
||||
import { TaskDialogComponentParams } from 'sql/services/bootstrap/bootstrapParams';
|
||||
import { ITaskDialogComponentParams } from 'sql/services/bootstrap/bootstrapParams';
|
||||
import { ElementRef, Component, Inject, forwardRef } from '@angular/core';
|
||||
import { IBootstrapParams } from 'sql/services/bootstrap/bootstrapService';
|
||||
|
||||
export const TASKDIALOG_SELECTOR: string = 'taskdialog-component';
|
||||
|
||||
@@ -19,17 +19,14 @@ export class TaskDialogComponent {
|
||||
|
||||
private _currentComponent: ITaskDialogComponent;
|
||||
|
||||
private _parameters: TaskDialogComponentParams;
|
||||
|
||||
public ownerUri: string;
|
||||
|
||||
public connection: ConnectionManagementInfo;
|
||||
|
||||
constructor(
|
||||
@Inject(forwardRef(() => ElementRef)) private _el: ElementRef,
|
||||
@Inject(BOOTSTRAP_SERVICE_ID) private _bootstrapService: IBootstrapService
|
||||
@Inject(IBootstrapParams) private _parameters: ITaskDialogComponentParams
|
||||
) {
|
||||
this._parameters = this._bootstrapService.getBootstrapParams(this._el.nativeElement.tagName);
|
||||
this.ownerUri = this._parameters.ownerUri;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import 'vs/css!sql/parts/query/editor/media/queryEditor';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { Dimension, Builder } from 'vs/base/browser/builder';
|
||||
import { EditorOptions } from 'vs/workbench/common/editor';
|
||||
@@ -11,11 +12,12 @@ import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
import { TaskDialogInput } from './taskDialogInput';
|
||||
import { IBootstrapService } from 'sql/services/bootstrap/bootstrapService';
|
||||
import { TaskDialogComponentParams } from 'sql/services/bootstrap/bootstrapParams';
|
||||
import { ITaskDialogComponentParams } from 'sql/services/bootstrap/bootstrapParams';
|
||||
import { TaskDialogModule } from 'sql/parts/tasks/dialog/taskDialog.module';
|
||||
import { TASKDIALOG_SELECTOR } from 'sql/parts/tasks/dialog/taskDialog.component';
|
||||
import { bootstrapAngular } from 'sql/services/bootstrap/bootstrapService';
|
||||
|
||||
export class TaskDialogEditor extends BaseEditor {
|
||||
|
||||
@@ -24,8 +26,7 @@ export class TaskDialogEditor extends BaseEditor {
|
||||
constructor(
|
||||
@ITelemetryService telemetryService: ITelemetryService,
|
||||
@IThemeService themeService: IThemeService,
|
||||
@IInstantiationService private instantiationService: IInstantiationService,
|
||||
@IBootstrapService private _bootstrapService: IBootstrapService
|
||||
@IInstantiationService private instantiationService: IInstantiationService
|
||||
) {
|
||||
super(TaskDialogEditor.ID, telemetryService, themeService);
|
||||
}
|
||||
@@ -88,10 +89,10 @@ export class TaskDialogEditor extends BaseEditor {
|
||||
private bootstrapAngular(input: TaskDialogInput): void {
|
||||
|
||||
// Get the bootstrap params and perform the bootstrap
|
||||
let params: TaskDialogComponentParams = {
|
||||
let params: ITaskDialogComponentParams = {
|
||||
ownerUri: input.getUri()
|
||||
};
|
||||
let uniqueSelector = this._bootstrapService.bootstrap(
|
||||
let uniqueSelector = this.instantiationService.invokeFunction(bootstrapAngular,
|
||||
TaskDialogModule,
|
||||
this.getContainer().getHTMLElement(),
|
||||
TASKDIALOG_SELECTOR,
|
||||
|
||||
Reference in New Issue
Block a user