# 自动加载

Tiger 会自动扫描 src/app 目录,按功能分类加载,我们可以通过不用的类型装饰器来表示


# 模块分类

# 控制器类

使用 @Controller() 装饰器

import { Controller } from '@tiger/common'

@Controller('/example')
export class Example  {
  // ...
}

# 中间件类

使用 @Middleware() 装饰器

import { Middleware, MiddlewareInterface } from '@tiger/common'

@Middleware()
export class Example implements MiddlewareInterface {
  resolve(request, next) {
    // ...
    return next()
  }
}

中间件类需要实现 MiddlewareInterface 接口

# 服务类

使用 @Service() 装饰器

import { Service } from '@tiger/common'

@Service()
export class Example {
  // ...
}

# 通用类

import { Component } from '@tiger/common'

@Component()
export class Example {
  // ...
}


# 模块命名

使用框架提供的 @Service(), @Component() 等装饰器来为模块进行重命名操作(实际上增加了绑定到容器的 key)。

import { Service } from '@tiger/common'

@Service()
export class Example {
  sayHello() {
    return 'hello tiger';
  }
}

自动识别类型进行注入





 









import { Controller, Get, Autowried } from '@tiger/common';
import ExampleService from '../service/example'

@Controller('/examples')
export default class Example {
  @Autowried
  exampleService: ExampleService;

  @Get()
  index() {
    return this.exampleService.sayHello()
  }
}

依赖注入详见 依赖注入 章节