Giter Site home page Giter Site logo

Comments (4)

B4nan avatar B4nan commented on September 2, 2024

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.

jsprw avatar jsprw commented on September 2, 2024

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.

B4nan avatar B4nan commented on September 2, 2024

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:

nestjs/nest#1870

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.

jsprw avatar jsprw commented on September 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.