mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Refactor to remove controller and static instance (#5735)
This commit is contained in:
@@ -16,6 +16,7 @@ export enum AzureResourceItemType {
|
||||
}
|
||||
|
||||
export enum AzureResourceServiceNames {
|
||||
resourceService = 'AzureResourceService',
|
||||
cacheService = 'AzureResourceCacheService',
|
||||
accountService = 'AzureResourceAccountService',
|
||||
subscriptionService = 'AzureResourceSubscriptionService',
|
||||
|
||||
@@ -12,11 +12,11 @@ import { azureResource } from './azure-resource';
|
||||
import { IAzureResourceNodeWithProviderId } from './interfaces';
|
||||
|
||||
export class AzureResourceService {
|
||||
private constructor() {
|
||||
}
|
||||
private _areResourceProvidersLoaded: boolean = false;
|
||||
private _resourceProviders: { [resourceProviderId: string]: azureResource.IAzureResourceProvider } = {};
|
||||
private _treeDataProviders: { [resourceProviderId: string]: azureResource.IAzureResourceTreeDataProvider } = {};
|
||||
|
||||
public static getInstance(): AzureResourceService {
|
||||
return AzureResourceService._instance;
|
||||
public constructor() {
|
||||
}
|
||||
|
||||
public async listResourceProviderIds(): Promise<string[]> {
|
||||
@@ -121,9 +121,4 @@ export class AzureResourceService {
|
||||
this._treeDataProviders[resourceProvider.providerId] = resourceProvider.getTreeDataProvider();
|
||||
}
|
||||
|
||||
private _areResourceProvidersLoaded: boolean = false;
|
||||
private _resourceProviders: { [resourceProviderId: string]: azureResource.IAzureResourceProvider } = {};
|
||||
private _treeDataProviders: { [resourceProviderId: string]: azureResource.IAzureResourceTreeDataProvider } = {};
|
||||
|
||||
private static readonly _instance = new AzureResourceService();
|
||||
}
|
||||
@@ -15,14 +15,19 @@ import { AzureResourceService } from './resourceService';
|
||||
import { IAzureResourceNodeWithProviderId } from './interfaces';
|
||||
import { AzureResourceMessageTreeNode } from './messageTreeNode';
|
||||
import { AzureResourceErrorMessageUtil } from './utils';
|
||||
import { AppContext } from '../appContext';
|
||||
import { AzureResourceServiceNames } from './constants';
|
||||
|
||||
export class AzureResourceResourceTreeNode extends TreeNode {
|
||||
private _resourceService: AzureResourceService;
|
||||
|
||||
public constructor(
|
||||
public readonly resourceNodeWithProviderId: IAzureResourceNodeWithProviderId,
|
||||
parent: TreeNode
|
||||
parent: TreeNode,
|
||||
private appContext: AppContext
|
||||
) {
|
||||
super();
|
||||
|
||||
this._resourceService = appContext.getService<AzureResourceService>(AzureResourceServiceNames.resourceService);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@@ -36,12 +41,12 @@ export class AzureResourceResourceTreeNode extends TreeNode {
|
||||
const children = await this._resourceService.getChildren(this.resourceNodeWithProviderId.resourceProviderId, this.resourceNodeWithProviderId.resourceNode);
|
||||
|
||||
if (children.length === 0) {
|
||||
return [AzureResourceMessageTreeNode.create(AzureResourceResourceTreeNode.noResourcesLabel, this)];
|
||||
return [AzureResourceMessageTreeNode.create(localize('azure.resource.resourceTreeNode.noResourcesLabel', 'No Resources found'), this)];
|
||||
} else {
|
||||
return children.map((child) => {
|
||||
// To make tree node's id unique, otherwise, treeModel.js would complain 'item already registered'
|
||||
child.resourceNode.treeItem.id = `${this.resourceNodeWithProviderId.resourceNode.treeItem.id}.${child.resourceNode.treeItem.id}`;
|
||||
return new AzureResourceResourceTreeNode(child, this);
|
||||
return new AzureResourceResourceTreeNode(child, this, this.appContext);
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -73,7 +78,4 @@ export class AzureResourceResourceTreeNode extends TreeNode {
|
||||
return this.resourceNodeWithProviderId.resourceNode.treeItem.id;
|
||||
}
|
||||
|
||||
private _resourceService = AzureResourceService.getInstance();
|
||||
|
||||
private static readonly noResourcesLabel = localize('azure.resource.resourceTreeNode.noResourcesLabel', 'No Resources found.');
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import { azureResource } from '../azure-resource';
|
||||
import { TreeNode } from '../treeNode';
|
||||
import { IAzureResourceNodeWithProviderId } from '../interfaces';
|
||||
import { AzureResourceContainerTreeNodeBase } from './baseTreeNodes';
|
||||
import { AzureResourceItemType } from '../constants';
|
||||
import { AzureResourceItemType, AzureResourceServiceNames } from '../constants';
|
||||
import { IAzureResourceTreeChangeHandler } from './treeChangeHandler';
|
||||
import { AzureResourceMessageTreeNode } from '../messageTreeNode';
|
||||
import { AzureResourceErrorMessageUtil } from '../utils';
|
||||
@@ -39,7 +39,7 @@ export class AzureResourceSubscriptionTreeNode extends AzureResourceContainerTre
|
||||
|
||||
public async getChildren(): Promise<TreeNode[]> {
|
||||
try {
|
||||
const resourceService = AzureResourceService.getInstance();
|
||||
const resourceService = this.appContext.getService<AzureResourceService>(AzureResourceServiceNames.resourceService);
|
||||
|
||||
const children: IAzureResourceNodeWithProviderId[] = [];
|
||||
|
||||
@@ -53,7 +53,7 @@ export class AzureResourceSubscriptionTreeNode extends AzureResourceContainerTre
|
||||
return children.map((child) => {
|
||||
// To make tree node's id unique, otherwise, treeModel.js would complain 'item already registered'
|
||||
child.resourceNode.treeItem.id = `${this._id}.${child.resourceNode.treeItem.id}`;
|
||||
return new AzureResourceResourceTreeNode(child, this);
|
||||
return new AzureResourceResourceTreeNode(child, this, this.appContext);
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -22,9 +22,7 @@ import { IAzureResourceAccountService } from '../../azureResource/interfaces';
|
||||
import { AzureResourceServiceNames } from '../constants';
|
||||
|
||||
export class AzureResourceTreeProvider implements TreeDataProvider<TreeNode>, IAzureResourceTreeChangeHandler {
|
||||
public constructor(
|
||||
public readonly appContext: AppContext
|
||||
) {
|
||||
public constructor(public readonly appContext: AppContext) {
|
||||
}
|
||||
|
||||
public async getChildren(element?: TreeNode): Promise<TreeNode[]> {
|
||||
|
||||
Reference in New Issue
Block a user