Comments (9)
no, it should not depend on number of injections. Can you provide a demo repo with problem reproduction so I can take a closer look?
from typedi.
Unfortunately application where I'm using injections is rather large, so it will be problematic to reproduce the problem.
I'll try to debug place mentioned in the error, maybe there something trying to be service and it cannot
Created an issue for reason - maybe you know such case or something. I'll update it soon.
from typedi.
@pleerock what I learned - the error exists when I'm using service inside another service. When I use @Inject() in controllers - everything is ok.
Also I learned that service which causes errors - extending abstract class (which is not service but just class for some services to extend, with basic functionality). There are several other services which extends this abstract class.
I will try to investigate more, but maybe this info will tell you something.
It seems it fails at registering service somehow.
I tried to add name to this service (which extends abstract class), add @service decorator, but it won't be registered. Even when adding @service to abstract class and service.
I tried getting it before server start (but after getting connection to database) to register it before everything (it doesn't even have other @Inject() yet), but looks like it conflicts heavily with typeorm loading metadata or something via reflection. (errors cannot guess type of column, define type as argument via ColumnTypes)
Interesting. For now I'm not using heavily this service, but I will look further into it.
from typedi.
most probably you have circular reference issue. Its not have to be A <-> B
, it also can be A <- B <- C <-D <- E <- A
from typedi.
@pleerock maybe it's that. Maybe this is the issue?
this is service which dies. It uses class IntroLocation (which is not service, because there will be numerous classes like this, also they should be found by name in this my "container".
LocationService will register at least ~20 such classes in the future. For getting by name: string, for creating instances etc.
But there is IntroLocation, which has these usages:
And many other classes similar to IntroLocation will have usages of many services.
As you can see I pointed inventoryService. Which uses service which uses LocationService.
I guess that's where it dies. Is there any way I can define type or something in Container.get() ?
from typedi.
why are you using Container.get
and not regular constructor injection? I need a smallest possible reproduction example, but Im quite sure you have this issue because of circular dependencies.
from typedi.
@pleerock because IntroLocation is class which registered tighly coupled with it's name property in my own container for locations.
When using any kind of injection - since I'm doing new IntroLocation() in my container (not typedi) manually (registering it there) - it would not trigger any kind of injection.
Basically making service out of IntroLocation since it is registered in different place - is not possible.
IntroLocation is not a service. But it should be able to use services.
I will try to create reproduction example when I will use it again and post here.
from typedi.
closing now, don't really have time to provide example.
For those seeking I must say at least one thing: if you have objects that do use entityManager, another services outside "scope of container", where decorator-dependencies are not possible:
use Container.get inside constructor of those objects. Error exists because of getting services in the scope of module, initializing them not at the time of usage, but at the time of importing modules.
not right:
const service = Container.get(Service);
export class A {
// Using somewhere service
}
right:
export class A {
private service: Service = Container.get(Service);
}
from typedi.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
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: is this project/repo dead? HOT 5
- question: <Implementing repository injection using typedi-typeorm.> HOT 3
- question: <Is it possible to adapt your DI to work with modules (not classes)?> HOT 1
- question: HOT 3
- fix: Error when running in bunjs runtime HOT 2
- fix: not working function dependency injection examples from docs HOT 3
- question: Inject Private Property HOT 2
- 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.