While creating a dynamic module in Nest.js should i use registerAsync or forRootAsync?

前端 未结 1 1750
挽巷
挽巷 2021-01-05 21:05

While creating a dynamic module some of the nestjs modules are using registerAsync() some use forRootAsync(). which is the recommended meth

1条回答
  •  感情败类
    2021-01-05 21:17

    The names are just conventions and do not influence your application's behavior. Nevertheless, it is important to choose a name that properly fits your use case. I would consider the following criteria:

    If your module has to be imported differently in root/child modules, then stick with forRoot/forChild.

    Otherwise, use a name that describes your use case. Why do you need a dynamic import in the first place and what does it do? For instance:
    MyDatabaseModule.populate(data) vs. MyDatabaseModule.createConnection(configuration)

    Not all dynamic modules are actually asynchronous. So only use the postfix async if your import actually is (or can be) asynchronous. This also gives you the opportunity to offer both a synchronous and an asynchronous variant of the import.

    0 讨论(0)
提交回复
热议问题