Nj Request Scope

screenshot of Nj Request Scope
nestjs

Performant request scope dependency injection for NestJS framework using express server

Overview

The nj-request-scope library addresses the complexities of request-scope dependency injection in the NestJS framework when using an Express server. It targets common performance issues often encountered when handling request-scoped objects by utilizing the JavaScript Proxy design pattern. Instead of generating new instances for every dependency in the injection chain, it smartly alters only the target object for the new request-scope instance, enhancing overall performance and efficiency.

This library has been thoroughly tested across various NestJS versions, ensuring compatibility and stability for developers looking to streamline their injection processes. With a simple installation and clear usage instructions, nj-request-scope presents itself as a practical solution for developers looking to optimize their applications.

Features

  • Performance Optimization: Reduces the overhead of creating multiple instances in the injection chain by using a Proxy design pattern.
  • Seamless Integration: Works effortlessly with NestJS modules by accommodating the RequestScopeModule.
  • Express Compatibility: Specifically designed for Express servers, providing tailored solutions for common pitfalls in request-scope management.
  • Tokenized Injection: Allows for direct injection of the express request object into class constructors using the NJRS_REQUEST token.
  • Decorator Support: Facilitates changing the class injection scope to request-scope easily with the @RequestScope() decorator.
  • Limited Proxy Methods: While it implements common methods like get, has, and ownKeys, it allows contributions for further enhancements.
  • Broad Compatibility: Tested and validated with multiple versions of NestJS, from 8.x to 11.x, ensuring wide usability across different projects.
nestjs
Nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript.

typescript
Typescript

TypeScript is a superset of JavaScript, providing optional static typing, classes, interfaces, and other features that help developers write more maintainable and scalable code. TypeScript's static typing system can catch errors at compile-time, making it easier to build and maintain large applications.