Skip to content

Commit

Permalink
Merge pull request nestjs#2819 from f-w/f-w-patch-1-1
Browse files Browse the repository at this point in the history
Update components.md
  • Loading branch information
kamilmysliwiec authored Aug 9, 2023
2 parents 331ed6a + bd100ea commit 8990f31
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion content/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class HttpService<T> {
}
```

> warning **Warning** If your class doesn't extend another provider, you should always prefer using **constructor-based** injection.
> warning **Warning** If your class doesn't extend another class, you should always prefer using **constructor-based** injection.
#### Provider registration

Expand Down
2 changes: 1 addition & 1 deletion content/fundamentals/provider-scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Request-scoped providers, as mentioned in the section above, may lead to increas

Having a common provider that most providers depend on (think of a database connection, or a logger service), automatically converts all those providers to request-scoped providers as well. This can pose a challenge in **multi-tenant applications**, especially for those that have a central request-scoped "data source" provider that grabs headers/token from the request object and based on its values, retrieves the corresponding database connection/schema (specific to that tenant).

For instance, let's say you have an application alternately used by 10 different customers. Each customer has its **own dedicated data source**, and you want to make sure customer A will never be able to reach customer's B database. One way to achieve this could be to declare a request-scoped "data source" provider that - based on the request object - determines what's the "current customer" and retrieves its corresponding database. With this approach, you can turn your application into a multi-tenant application in just a few minutes. But, a major downside to this approach is that since most likely a large chunk of your application' components rely on the "data source" provider, they will implicitly become "request-scoped", and therefore you will undoubtedly see an impact in your apps performance.
For instance, let's say you have an application alternately used by 10 different customers. Each customer has its **own dedicated data source**, and you want to make sure customer A will never be able to reach customer B's database. One way to achieve this could be to declare a request-scoped "data source" provider that - based on the request object - determines what's the "current customer" and retrieves its corresponding database. With this approach, you can turn your application into a multi-tenant application in just a few minutes. But, a major downside to this approach is that since most likely a large chunk of your application' components rely on the "data source" provider, they will implicitly become "request-scoped", and therefore you will undoubtedly see an impact in your apps performance.

But what if we had a better solution? Since we only have 10 customers, couldn't we have 10 individual [DI sub-trees](/fundamentals/module-ref#resolving-scoped-providers) per customer (instead of recreating each tree per request)? If your providers don't rely on any property that's truly unique for each consecutive request (e.g., request UUID) but instead there're some specific attributes that let us aggregate (classify) them, there's no reason to _recreate DI sub-tree_ on every incoming request.

Expand Down

0 comments on commit 8990f31

Please sign in to comment.