Comments (4)
Not really, there were some issues with that, iirc it was something with JWT middleware not supporting the nest di request scope.
But we could have that available optionally, agreed it would be cleaner. Btw it is now possible to disable the automatic request scope middleware registration.
from nestjs.
I have been using a modified provider of the EnitityManager token and it's working fine for me (disabled the request context option):
export const createMikroOrmEntityManagerProvider = (
alias?: string
): Provider => ({
provide: alias ?? EntityManager,
scope: Scope.REQUEST,
useFactory: (orm: MikroORM) => orm.em.fork(),
inject: [MikroORM],
});
I could create a PR with this change for you to test it (altough it's an easy fix)?
from nestjs.
The thing is that the native request scope from nest does not work with things like their JWT service. This is the issue I am talking about:
This is for me the main reason why to prefer the RequestScope
solution (that can be nowadays also replaced with AsyncLocalStorage
), as it just works. Also it is arguable that using the nest DI is "better". It will instantiate all the classes for you for each request, which will have a performance impact. And it is not just about the EM or repositories - this applies to all classes that are dependent on anything ORM related, so most probably all of your services and controllers. The domain
api solution also have impact, but when replaced with the AsyncLocalStorage
, there was almost no overhead.
So again, I am fine with supporting this optionally, feel free to send a PR, but it needs to be configurable, and I would keep the RequestContext
solution as the default.
from nestjs.
See my comment here why I prefer using this over RequestContext: mikro-orm/mikro-orm#315 (comment). Angular's zone.js and with this approach of getting the repositories you can't really use the Zone'js solution that easy either.
Alright, will create a PR in a bit.
from nestjs.
Related Issues (20)
- Error when trying to query an entity from the repository HOT 3
- How can I take some actions after it successfully connects or fails? HOT 1
- Cannot persist an entity with a 1-to-1 reference to another entity HOT 5
- Cannot persist Read-Only association HOT 3
- Cannot get `@UseRequestContext` to work in a REQUEST scoped BullMQ processor HOT 4
- Populating Nested Field returns the wrong number of associated entities HOT 5
- Relations not working in nestjs HOT 6
- Issue when running tests after upgrading to 5.2.2
- Bump version, compatible with MikroORM V6 HOT 6
- Nestjs, mikro-orm and postgres can't generate table automatically HOT 2
- vitest + mikroorm collection error HOT 4
- findByCursor method not working on sqlite HOT 1
- Testing with multiple testing modules in NestJS and Jest leads to an error during metadata discovery HOT 2
- Issues running Mikro-ORM with NestJS on Vercel platform HOT 1
- MikroOrmMiddleware not found in e2e tests
- feat: add Transactional Decorator HOT 1
- How to listen to connection status?
- Nest cannot export a provider/module that is not a part of the currently processed module (MikroOrmCoreModule). Please verify whether the exported MongoMikroORM is available in this particular context.
- Allow specifying .fork() options for Request-Scoped EntityManager in the MikroOrmModule
- Using multiple databases hustle
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nestjs.