import { Config , Init , Inject , Provide , Scope , ScopeEnum , } from '@midwayjs/decorator' ; import * as TableStore from 'tablestore' ; import { ServiceFactory , delegateTargetPrototypeMethod } from '@midwayjs/core' ; import { TableStoreClient } from './interface' ; @ Provide ( ) @ Scope ( ScopeEnum . Singleton ) export class TableStoreServiceFactory extends ServiceFactory < TableStoreClient > { @ Config ( 'tableStore' ) tableStoreConfig ; @ Init ( ) async init ( ) { await this . initClients ( this . tableStoreConfig ) ; } async createClient ( config ) { return new TableStore . Client ( config ) as any ; } getName ( ) { return 'tableStore' ; } } @ Provide ( ) @ Scope ( ScopeEnum . Singleton ) export class TableStoreService implements TableStoreClient { @ Inject ( ) private serviceFactory : TableStoreServiceFactory ; private instance : OSS ; @ Init ( ) async init ( ) { this . instance = this . serviceFactory . get ( 'default' ) ; } } export interface TableStoreService extends TableStoreClient { } delegateTargetPrototypeMethod ( TableStoreService , [ TableStore . Client ] ) ;