feat: remove auto connect use manual inject

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2019-10-18 14:26:26 +08:00
parent 5fa5603735
commit 140f881062
8 changed files with 37 additions and 50 deletions

View File

@@ -1,10 +1,8 @@
import { DBClient } from '@cc-server/db'
import { inject, postConstruct } from '@cc-server/ioc';
import { inject, named } from '@cc-server/ioc';
import { Vaild, NotBlank, NotNull, controller, requestBody, get, post, requestParam } from '@cc-server/binding'
import '@cc-server/db-mongo'
const TABLE = 'users'
class ExampleModel {
_id: string;
@NotBlank("username must not be blank!")
@@ -18,13 +16,9 @@ class ExampleModel {
@controller('/example')
export class Controller {
@inject(DBClient)
@named("users")
private client: DBClient
@postConstruct()
private init(): void {
this.client.setTable(TABLE);
}
@get('/')
public async list(): Promise<ExampleModel[]> {
return this.client.find({});