Comments (2)
That is expected, private fields cannot be decorated by design. However, you can try to create a getter and decorate that. (I havenโt tried it myself, but the spec allows it)
from typedi.
@attilaorosz - this is not true. It used to work in earlier versions. Started to acting up around 0.8.0. Currently with 0.10.0 I find, that @Inject() works in one place in code and fails in others. Calling container directly via Container.get in the same place works with no issue.
This used to work but doesn't anymore with 0.10.0:
@Service()
@RestController('some-settings', 2)
export class SomeSettingsV2Resource {
@Inject()
private getAlHandler: GetAllHandler;
@Inject()
private getSomeSettingsHandler: GetSomeSettingsHandler;
}
this also doesn't work:
@Service()
@RestController('some-settings', 2)
export class SomeSettingsV2Resource {
constructor(
@Inject(() => GetAllHandler)
private readonly getAllHandler: GetAllHandler,
@Inject(() => GetSettingHandler)
private readonly getSettingHandler: GetSettingHandler
) {}
}
This works though:
@Service()
@RestController('some-settings', 2)
export class SomeSettingsV2Resource {
constructor(
private readonly getAllHandler: GetAllHandler = Container.get(GetAllHandler),
private readonly getSettingHandler: GetSettingHandler = Container.get(GetSettingHandler)
) {}
}
from typedi.
Related Issues (20)
- question: How do you test your services with dependency injection? HOT 32
- fix: Constructor Injection fail in vitest/jest HOT 3
- question: adding custom proxy traps in class constructors and instances HOT 2
- fix: non-reconstructable services are erased when imported HOT 1
- question: Stage 3 decorator support (available since TS 5.0)
- question: How to debug circular dependency injections ?
- Question: Service Injection working incorrectly HOT 1
- question: Typeorm 0.3.0 has deprecated all container-related features. What does this mean for TypeDi? HOT 2
- question: Getting "Class constructor MyService cannot be invoked without 'new'" HOT 2
- question: How do you destroy a scoped container? HOT 8
- fix: `importsNotUsedAsValues: remove` breaks DI HOT 3
- question: <How to use it with esbuild> HOT 5
- fix: not working function dependency injection examples from docs HOT 3
- Using ContainerInstance in the service constructor causes TypeScript build breaks HOT 1
- question: identifier was not found in the container HOT 2
- question: Using typedi with monorepo HOT 3
- question: Using Typedi with Vite - Returning ContainerInstance2 HOT 3
- question: How to define a third-party dependency HOT 5
- question: Using Token with Generics failed in stongly typying
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typedi.