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

Which container instance should I use ? #200

Open
alcalyn opened this issue Oct 18, 2023 · 2 comments
Open

Which container instance should I use ? #200

alcalyn opened this issue Oct 18, 2023 · 2 comments

Comments

@alcalyn
Copy link

alcalyn commented Oct 18, 2023

I found this library, and thanks to that, it is exactly what I was looking for !

I try to use it, I could use decorators for my express app, but I admit it was a little tricky, I don't find more documentation but readmes in differents project.

For the container, it's unclear whether I should use:

  • the instance in @decorators/express (works better for me)
  • the instance RootContainer in @decorators/di (makes more sense to me, but breaks my controllers using decorators)
  • create my own instance (why not, but same, I can't use decorators, services are registered in the express one)
  • @decorators/di, "Container" is the class, not an instance

I see in the example @decorators/server that it's using "Container", but seems to be outdated, as it uses di 1.0, I'm using the v3.

Is there an up-to-date example or documentation I can use ?

I also checked this issue #119 with the example, but also outdated I think, I can't use import { Container } from '@decorators/di';, it is a class, not an instance

@alcalyn
Copy link
Author

alcalyn commented Oct 18, 2023

I'm playing with express, socket io, and want to build more maintenable app using controllers as classes, separate all my websocket message in multiple classes/files and using decorators, use di...

@serhiisol
Copy link
Owner

serhiisol commented Nov 27, 2023

Hi @alcalyn you should use Container out of @decorators/express package. @decorators/di package returns few major things: RootContainer the singleton to work with and Container class to have an ability to create several containers. At the moment @decorators/express uses Container and creates its own root container. I think I would replace this behavior in favor of RootContainer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants