-
I want to know how to use it properly. part of my configuration.
Here's the question. I want to use EntityManager On Service Class(Provider).
I think 2 is proper way than 1. Because nestjs/src/mikro-orm.providers.ts Line 42 in 7dfc097 Is it right? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Both ways are doing the same, and actually the first one should be preferred. The point of using |
Beta Was this translation helpful? Give feedback.
Both ways are doing the same, and actually the first one should be preferred. The point of using
RequestContext
helper is to allow the 1. way. We still work with the fork internally, as all methods on the EM that are using the context somehow will first get the fork viaem.getContext()
, which is by default doingRequestContext.getEntityManager()
. You can check theem.id
, it should show you different values for each request, even if you use the instance from DI. Those instances in DI are always global, but when they are executed inside context handler (so inside the middleware handler), they will see the fork and use that instead. With v5 we even validate that you are not touching the glob…