Is there a recommended library to do dependency injection in Deno?
I'm creating a Rest API with the repository and controllers pattern but my code in the
main.ts
file keeps getting bigger and bigger
11 Replies
Have you tried any packages that are popular in nodejs ecosystem?
Maybe inversify, tsyringe
I tried with
npm:tsyringe
and ¡ it works !
Thanks for the response 👍
I will use it in my project@Joaquín Buendía do you know if it works on deno deploy?
Did you have to do anything to make it work?
Also ant specific Deno version?
I don't know if it works in deno deploy, my project runs on a docker image
I just followed the tsyringe documentation but using the
npm:
tagGitHub
GitHub - microsoft/tsyringe: Lightweight dependency injection conta...
Lightweight dependency injection container for JavaScript/TypeScript - GitHub - microsoft/tsyringe: Lightweight dependency injection container for JavaScript/TypeScript
My Deno version:
1.38.5
.
Docker image: denoland/deno:alpine-1.38.5
Thanks!
hey, can i know any 3rd party package that runs on Deno environment that do DI? I tried many packages but didn't work, or giving the error of "InvalidWorkerResponse"
Yes they work but bundle is needed
On deno cli works normally, on deploy bundle is needed
can i have more context on this as i'm new for DI. i'm using https://deno.land/x/alosaur@v0.9.0/src/injection/README.md?source= and followed everything as they mentioned. but still getting the "InvalidWorkerCreation" error
You can use Danet and leverage its custom DI system. It even provides a CLI to bundle for Deploy, a guide on how to do so manually, and a github action ready to use.