1.0.0 • Published 1 year ago

@aomex/service v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@aomex/service

项目服务层

初始化

pnpm add @aomex/service

使用方式

创建服务

// File: src/services/my.service.ts
import { Service } from '@aomex/service';

export class MyService extends Service {
  protected override async init() {
    // 做一些初始化操作
  }

  action1() {
    return 'ok';
  }

  async action2() {
    // 使用其他服务
    await this.services.other.actionX();
    ...
  }
}

服务组合

// File: src/services/index.ts
import { combineServices } from '@aomex/service';

export const services = await combineServices({
  my: MyService,
});

// 服务中可以安全地使用`this.services`
declare module '@aomex/service' {
  type T = typeof services;
  export interface CombinedServices extends T {}
}

使用服务

import { services } from '../services';

services.my.action1();
1.0.0

1 year ago

0.0.3

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago