Coder Social home page Coder Social logo

Comments (9)

pleerock avatar pleerock commented on May 17, 2024

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.

idchlife avatar idchlife commented on May 17, 2024

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.

idchlife avatar idchlife commented on May 17, 2024

@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.

pleerock avatar pleerock commented on May 17, 2024

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.

idchlife avatar idchlife commented on May 17, 2024

@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".

image

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:

image

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.

pleerock avatar pleerock commented on May 17, 2024

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.

idchlife avatar idchlife commented on May 17, 2024

@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.

idchlife avatar idchlife commented on May 17, 2024

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.

github-actions avatar github-actions commented on May 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.