Questions & Answers

How can I handle dependencies library, such as a database abstraction or logger?

Deepkit HTTP
50 up-votes
Warning: The answer is generated by an artificial intelligence. It might not be correct.
To adjust rating, open the thread in Discord and click on the up/down vote button.

Dependencies such as a database abstraction or logger can be handled by leveraging the power of Dependency Injection. These dependencies can be injected into controller methods or functional API routes via constructor injection or function parameter injection. For example:

class UserController {
    constructor(private database: Database) {}

    @http.GET('/user/:id')
    getUser(id: number) {
        // Use the database abstraction
    }
}

const app = new App({
    controllers: [UserController],
    imports: [new FrameworkModule()],
    providers: [Database]
});