does NitroJS (server of NuxtJS) support dependency injection as the following ?
call any dependency from the class constructor “dependency injection: inversion of control (IoC)” and let the framework get/initialize it from the singleton reflection like laravel and nestJS as below examples
<?php
namespace AppHttpControllers;
use AppRepositoriesUserRepository;
class UserController extends Controller
{
/**
* Create a new controller instance.
*/
public function __construct(
protected UserRepository $users,
) {}
}
Laravel example:
import { Controller, Get, Bind, Dependencies } from '@nestjs/common';
import { CatsService } from './cats.service';
@Controller('cats')
@Dependencies(CatsService)
export class CatsController {
constructor(catsService) {
this.catsService = catsService;
}
@Get()
async findAll() {
return this.catsService.findAll();
}
}
nestJS example:
use dependency injection at NitroJS (server of NuxtJS)
New contributor
Abdallah Zaghloul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.