loading...

re: Sharing the context with the model in an Express app VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Hi Kryz! thanks for your comment! I like your idea! I wasn't sure about modifying the prototype in the middleware, I like your approach, but I thi...
 

Hi,
I like your idea!

One more thing - the middleware runs the factory on each request, is it good for the application performance?

Maybe it would be better to delay this calls, for example:

  const models = {
    project: () => ...here your factory call
  };

  req.context.models = models;

and in the controller something like this:

const projectModel = req.context.models.project();

I know, it doesn't look nice, I'm sure there is a better solution..

Code of Conduct Report abuse