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

question: what is the point of Inject if we can use Container.get #1365

Open
fake364 opened this issue Jul 30, 2024 · 0 comments
Open

question: what is the point of Inject if we can use Container.get #1365

fake364 opened this issue Jul 30, 2024 · 0 comments
Labels
type: question Questions about the usage of the library.

Comments

@fake364
Copy link

fake364 commented Jul 30, 2024

I was trying to find an answer and there were questions that sounded similar but they didn't answer question.
So the question is: What is the point to use @Inject decorator if we can use Container.get ? Besides getting an instance of the service Container.get initializes all dependencies on target class (why don't we have separate method for that). But I noticed that if I don't use Container.get, Inject would leave all dependencies undefined. So if I don't want to use Container.get anywhere why can't I use just @service and @Inject as I intended to use Inject as if it would have been Container.get?

@Service
class Test {
private field=Container.get(Service2)
}

So how to use Inject and Service and make all services initialized with dependencies without writing Container.get for all services.

Also I noticed that it won't inject recursively all dependencies e.g. if I have following structure

@Service
class CommentsService {
@Inject
otherService...
...
}

@Service
class CommentsController {
@Inject
commentsService:CommentsService;
....
}

@Service
class CommentsRoute {
@Inject
commentsController:CommentsController;
.....
}
app.use([Container.get(CommentsRoute)])

So the only way to use that I see

@Service
class CommentsService {
@Inject
otherService...
...
}

@Service
class CommentsController {
commentsService=Container.get(CommentsService);
....

printSomething(){
this.commentsService.print()
}
}
@fake364 fake364 added the type: question Questions about the usage of the library. label Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Questions about the usage of the library.
Development

No branches or pull requests

1 participant