feat: remove auto connect use manual inject
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
@@ -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({});
|
||||
|
||||
Reference in New Issue
Block a user