简体   繁体   English

如果节点中的所有内容都是模块,那么 NestJs 中的模块有什么意义?

[英]if everything in node is a module than what is the point of modules in NestJs?

why not simply use folders instead of modules if the only purpose is to make the structure more organized?如果唯一的目的是使结构更有条理,为什么不简单地使用文件夹而不是模块呢?

It is weird because it does not seem necessary since every file is a separate module in node.js and if i need anything i have to import it using the import statement anyways so what is the point of specifying the imports and exports in a module?这很奇怪,因为它似乎没有必要,因为每个文件都是 node.js 中的一个单独模块,如果我需要任何东西,我无论如何都必须使用import语句导入它,那么在模块中指定导入和导出有什么意义呢? does it affect the dependency injection if i just import what i need without using modules(@Module decorator) or something similar?如果我只导入我需要的而不使用模块(@Module 装饰器)或类似的东西,它会影响依赖注入吗?

NestJs has opted to design their framework with dependency injection as one of its core principals. NestJs 选择将依赖注入作为其核心原则之一来设计他们的框架。 Ie, you write your code just using the name/type of the services you want to use, and then a different piece of code is responsible for finding that service, knowing how to construct it, and then passing it in to you.即,您仅使用要使用的服务的名称/类型编写代码,然后另一段代码负责查找该服务,知道如何构建它,然后将其传递给您。

Native import / export doesn't have a system for dependency injection, so the main thing that the @Module decorator does is organize the metadata needed for the injector system.原生import / export没有依赖注入系统,所以@Module装饰器做的主要事情是组织注入器系统所需的元数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM