You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lib/src/service/Controllers.ts

24 lines
902 B

import {CanonicalStatic} from "./CanonicalStatic";
import {Singleton, Instantiable} from "../di";
import {Controller} from "../http/Controller";
import {CanonicalDefinition} from "./Canonical";
/**
* A canonical unit that loads the controller classes from `app/http/controllers`.
*/
@Singleton()
export class Controllers extends CanonicalStatic<Instantiable<Controller>, Controller> {
protected appPath = ['http', 'controllers']
protected canonicalItem = 'controller'
protected suffix = '.controller.js'
public async initCanonicalItem(definition: CanonicalDefinition) {
const item = await super.initCanonicalItem(definition)
if ( !(item.prototype instanceof Controller) ) {
throw new TypeError(`Invalid controller definition: ${definition.originalName}. Controllers must extend from @extollo/lib.http.Controller.`)
}
return item
}
}