2.0 Application module
Declaring a root or application module ( application.ts ) and root module requires Logger, Router providers to be provided and those services are built-in framework.
import {Module, Logger, Inject, IAfterConstruct, Router, Methods, LogLevels} from "typeix";
import {Assets} from "./components/assets";
import {HomeController} from "./controllers/home";
import {TemplateEngine} from "./components/mu2";
/**
* Application entry point
* @constructor
* @function
* @name Application
*
* @description
* \@Module is used to define application entry point class
*/
@Module({
controllers: [HomeController], // controllers attached to this module
providers: [
/**
* Logger is provided as factory because we want to configure logger before all modules
* are instanceiated (Modules are resolved and instanciated recursivley once)
*/
{
provide: Logger,
useFactory: () => {
let logger: Logger = new Logger();
logger.enable();
logger.printToConsole();
logger.setDebugLevel(LogLevels.BENCHMARK);
return logger;
},
deps: []
},
Router,
Assets,
TemplateEngine
] // services attached to this module
})
export class Application implements IAfterConstruct {
@Inject(Router)
router: Router;
/**
* @function
* @name Application#afterConstruct
*
* @description
* After construct use injected values to define some behavior at entry point
* Defining main route, all routes are processed
*/
afterConstruct() {
this.router.addRules([
{
methods: [Methods.GET],
route: "home/favicon",
url: "/favicon.ico"
},
{
methods: [Methods.GET],
route: "home/index",
url: "/"
}
]);
}
}