Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TypeDI do not inject service #1241

Open
Mullayam opened this issue Sep 28, 2023 · 4 comments
Open

fix: TypeDI do not inject service #1241

Mullayam opened this issue Sep 28, 2023 · 4 comments
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@Mullayam
Copy link

TypeDI was not able to inject sercie container in controller

Here is my code
i've tried all method written in documentation but still get error

image
image
image
image

Expected behavior

it should inject the dependencies and return json

Actual behavior

TypeError: this.test.getName is not a function
at BaseController.index (file:///E:/private/noidejs/nodets-pack/src/controllers/collection/base.controller.ts:14:28)
at ActionMetadata.callMethod (E:\private\noidejs\nodets-pack\node_modules.pnpm@[email protected][email protected][email protected]\node_modules@enjoys\main\metadata\ActionMetadata.ts:252:44)
at E:\private\noidejs\nodets-pack\node_modules.pnpm@[email protected][email protected][email protected]\node_modules@enjoys\main\RoutingControllers.ts:123:28
at processTicksAndRejections (node:internal/process/task_queues:95:5)

@Mullayam Mullayam added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Sep 28, 2023
@attilaorosz
Copy link
Member

attilaorosz commented Sep 28, 2023

Did you import reflect-metadata?

@L-Chris
Copy link

L-Chris commented Aug 1, 2024

same problem. It's ok in development mode, but crashed in production mode.

@L-Chris
Copy link

L-Chris commented Aug 1, 2024

my package.json
{ "name": "koa-ts", "version": "3.2.1", "license": "MIT", "description": "The best practice of building Koa2 with TypeScript", "main": "app.ts", "scripts": { "dev": "cross-env NODE_ENV=development; ts-node-dev -r tsconfig-paths/register app.ts", "dev:crawler": "cross-env NODE_ENV=development; ts-node-dev -r tsconfig-paths/register app/jobs/index.ts", "dev:import": "cross-env NODE_ENV=development; ts-node-dev -r tsconfig-paths/register app/jobs/import_library.ts", "dev:db": "docker compose -f docker-compose.yml up -d", "prettier": "prettier --write '**/*.{js,ts}'", "test": "jest --config .jest.config.js --no-cache --detectOpenHandles", "prod:build": "node ./build.js", "prod:start": "prisma generate && prisma migrate deploy && cross-env NODE_ENV=production; node ./dist/index.js", "prod:run": "npm run prod:build && cross-env NODE_ENV=production; node ./dist/index.js" }, "author": "unix ([email protected])", "bugs": { "url": "https://github.com/unix/koa-ts/issues" }, "repository": "[email protected]:unix/koa-ts.git", "engines": { "node": ">= 14.x" }, "prettier": "@geist-ui/prettier-config", "devDependencies": { "@babel/plugin-proposal-export-namespace-from": "^7.18.9", "@babel/plugin-transform-modules-commonjs": "^7.24.8", "@babel/preset-typescript": "^7.24.7", "@geist-ui/prettier-config": "^1.0.1", "@types/crawler": "^1.2.6", "@types/fast-levenshtein": "^0.0.4", "@types/jest": "^25.2.2", "@types/koa": "^2.13.4", "@types/koa-bodyparser": "^4.3.5", "@types/koa-static": "^4.0.4", "@types/node": "^17.0.8", "@types/node-cron": "^3.0.11", "esbuild": "^0.14.11", "esbuild-node-externals": "^1.4.1", "jest": "^26.6.3", "prettier": "^2.5.1", "prisma": "^4.6.1", "supertest": "^4.0.2", "ts-jest": "^26.5.3", "ts-node": "10.9.2", "ts-node-dev": "2.0.0", "tsconfig-paths": "^3.12.0", "typescript": "^4.9.5" }, "dependencies": { "@koa/cors": "^5.0.0", "@prisma/client": "^4.6.1", "axios": "^1.7.2", "class-transformer": "0.5.1", "class-validator": "0.14.0", "crawler": "^1.5.0", "cross-env": "^7.0.3", "dayjs": "^1.11.12", "dotenv": "^12.0.3", "fast-levenshtein": "^3.0.0", "fix-esm": "^1.0.1", "koa": "^2.13.4", "koa-bodyparser": "^4.3.0", "koa-logger": "^3.2.1", "koa-multer": "^1.0.2", "koa-router": "^10.1.1", "koa-static": "^5.0.0", "node-cron": "^3.0.3", "queue": "^7.0.0", "reflect-metadata": "^0.1.13", "routing-controllers": "0.10.4", "typedi": "^0.10.0" } }

@luisalbertodev
Copy link

You can see an example of hexagonal architecture with typedi for inject dependences

https://github.com/luisalbertodev/ddd-typescript-hexagonal-architecture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.
Development

No branches or pull requests

4 participants