nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.76k stars 7.64k forks source link

Decouple Nest's DI container from Node API #13222

Closed aventez closed 8 months ago

aventez commented 9 months ago

Is there an existing issue that is already proposing this?

Is your feature request related to a problem? Please describe it

My team and I are working on game software for GTA V multiplayer, where the gamemode (client+server) is written based on TS. We had the idea of using some of the Nest.js functionality on the client and server for DI IoC and good architecture.

image

The game API provides us with the V8 runtime for clientside and Node.js for serverside soft. Unfortunately, we are not able to run DI with Nest.js having only V8 at our disposal, as core Nest.js is strongly tied to the Node API (especially HTTPs). Nest could solve many problems.

Describe the solution you'd like

It can be great to decouple Nest.js core from Node.js API to make it possible to use with V8 runtime apps.

What is the motivation / use case for changing the behavior?

Many other applications could use Nest as an IoC/DI wrapper, making the framework even more elastic and not limited to backend solutions.

micalevisk commented 9 months ago

why not using alternatives like tsyringe? I believe you could build an API similar to NestJS on top of it

AFIAK Nest's DI container isn't something that was designed to live outside of nestjs, and so changing it to support v8 only would be hard.

aventez commented 9 months ago

AFIAK Nest's DI container isn't something that was designed to live outside of nestjs, and so changing it to support v8 only would be hard.

Probably it was - https://docs.nestjs.com/standalone-applications

why not using alternatives like tsyringe? I believe you could build an API similar to NestJS on top of it

We use Inversify and that's the only option, but having all the rest NestJS features just can be great

micalevisk commented 9 months ago

still, it's a nodejs framework

asking to support v8 only or anything not related with nodejs seems out of the scope of the fw to me

KostyaTretyak commented 9 months ago

@aventez, try the DI used in Ditsmod. It can work completely independent of Ditsmod. It is built on the basis of the Angular v4.4.7 native module.

import { Injector, injectable } from '@ditsmod/core';

class Service1 {}

@injectable()
class Service2 {
  constructor(service1: Service1) {}
}

@injectable()
class Service3 {
  constructor(service2: Service2) {}
}

const injector = Injector.resolveAndCreate([Service1, Service2, Service3]);
const service3 = injector.get(Service3);
service3 === injector.get(Service3); // true
service3 === injector.resolveAndInstantiate(Service3); // false
kamilmysliwiec commented 8 months ago

Thanks for your suggestion!

There are no plans to implement it in the foreseeable future.

If you think your request could live outside Nest's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.