NestJS uses a dependency injection system. This system allows TypeORM's database connection and repositories to be injected into any service or controller easily. This makes managing database connections and queries simple and consistent.
TypeORMModule.forRoot() creates and configures a single database connection that is shared globally. This means any service or controller can inject repositories or the connection without extra setup.
The @InjectRepository decorator from @nestjs/typeorm is used to inject the repository for a specific entity. Option C uses this correctly with the User entity.
The find() method returns an array of all User entities found. Since there are two records, users.length will be 2.
Without the @InjectRepository decorator, NestJS does not know to inject the TypeORM repository instance. It will throw a runtime error about missing provider.