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: Using typedi with monorepo #942

Open
Kimblis opened this issue Nov 16, 2022 · 3 comments
Open

question: Using typedi with monorepo #942

Kimblis opened this issue Nov 16, 2022 · 3 comments
Labels
type: question Questions about the usage of the library.

Comments

@Kimblis
Copy link

Kimblis commented Nov 16, 2022

I was trying to...
I was trying to use typedi with monorepo, where we have a common repo where we place some common stuff between other repos, so there are common services there as well.

The problem:
If I create service in that common repo, decorate it with @service decorator, I still can't inject it anywhere else, it throws ServiceNotFoundError. If I place the same services inside my repo I'm trying to access this service in - everything works just fine. However now I need to duplicate all these services in all repos which is not optimal... Is there are way to share these services between repos in monorepo structure? Any ideas would really be helpful

@Kimblis Kimblis added the type: question Questions about the usage of the library. label Nov 16, 2022
@attilaorosz
Copy link
Member

I’m using typedi in an nx monorepo without issues. Could you please create a simple reproduction repo on github so we can investigate?

@Kimblis
Copy link
Author

Kimblis commented Nov 16, 2022

Of course, created a public repo, you can start it up with 2 make commands from readme file. If you go to service2/src/services/Authentication.ts you will see that I try to reach Cryptography service. If I use Cryptography service defined in the same project (in the same folder in this case as well) - it works as it should, however if I use that CryptographyService from service1 - it does not...
https://github.com/Kimblis/typedi-monorepo-example

@attilaorosz
Copy link
Member

It seems to me that the node_modules resolution is a bit interesting in your repo. Because you have a node_modules folder for each app, the Service decorator gets resolved from their respective folders, resulting in multiple instances of Container.
In our nx monorepo, we have one shared node_modules folder so the resolution is fine.

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

2 participants