An onther style (like C#/java) of egg enterprise app framework.
egg-controller
export class HomeController extends Controller {
// 如果不需要访问ctx,则不需要继承
@route("/api/xxx", { name: "获取XXX数据" })
async getXXX(size: number, page: number) {
return "homeIndex";
}
}
egg-aop
export class TestService extends Service {
get(id: string | number) {
return {
id,
name: this.app.config.test + "_" + id
};
}
}
export class HomeController extends Controller {
@lazyInject()
testService: TestService;
@route("/api/xxx", { name: "获取XXX数据" })
async getXXX(id: string) {
return this.testService.get(id);
}
}
-
use egg-init to initialize a project.
-
config project.json add:
"egg": {
"framework": "egg-typed"
},
- An example of tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"preserveConstEnums": true,
"declaration": true,
"sourceMap": true,
"rootDir": "src",
"outDir": "app",
"pretty": true
}
}
Please open an issue here.