D
Deno

help

Is there a recommended library to do dependency injection in Deno?

JJgamer1y12/26/2023
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
// Repositories
const animeFavoritesRepo = new MongoAnimeFavoritesRepository(mongoDatabase);
const animesRepo = new MongoAnimesRepository(mongoDatabase);
const usersRepo = new MongoUsersRepository(mongoDatabase);
// .... more repos

// Routes
// I'm injectin the controllers and repos
const auth = new AuthRoutes(new AuthController(usersRepo), usersRepo).router();
app.use(auth.routes());
app.use(auth.allowedMethods());
// ... more routes
// Repositories
const animeFavoritesRepo = new MongoAnimeFavoritesRepository(mongoDatabase);
const animesRepo = new MongoAnimesRepository(mongoDatabase);
const usersRepo = new MongoUsersRepository(mongoDatabase);
// .... more repos

// Routes
// I'm injectin the controllers and repos
const auth = new AuthRoutes(new AuthController(usersRepo), usersRepo).router();
app.use(auth.routes());
app.use(auth.allowedMethods());
// ... more routes
ASAntonio Sampaio12/26/2023
Have you tried any packages that are popular in nodejs ecosystem? Maybe inversify, tsyringe
JJgamer1y12/26/2023
I tried with npm:tsyringe and ¡ it works ! Thanks for the response 👍 I will use it in my project
Ffro.profesional12/28/2023
@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?
JJgamer1y12/29/2023
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: tag
JJgamer1y12/29/2023
GitHub
GitHub - microsoft/tsyringe: Lightweight dependency injection conta...
Lightweight dependency injection container for JavaScript/TypeScript - GitHub - microsoft/tsyringe: Lightweight dependency injection container for JavaScript/TypeScript
JJgamer1y12/29/2023
My Deno version: 1.38.5. Docker image: denoland/deno:alpine-1.38.5
Ffro.profesional12/29/2023
Thanks!

Looking for more? Join the community!

Recommended Posts
React (CRA) deploy via denoGetting an error while building react CRA via deno deploy. Error: ENOENT: no such file or directoryCustom executable icon for `deno compile`?Is it possible to set a different icon rather than the default deno icon for the executable generateDeno.Command output as it runsHello, I am trying to run a command and have its output be logged as it runs , but for some reason telectrons using denoIn the recent deno version I see it is possible to runn executable in ./bin in node_modules using Cannot find moduleHi <:vmathi:812484657547313212> I'm trying to run a project with Deno, but i'm getting "Cannot find Uncaught error during deno deploy of vite appWhen creating a new vite app with vue and typescript I get this error message. This error is reprodDeno, TypeScript, ESBuild, WebGL, VSCodeHello! As the title suggests, I am using these technologies to create a web application: * Deno * TPossible issue with re-export compatibility with NodeIn https://github.com/japa/runner/issues/35, I have described an issue where Deno seems to be incompMake deno.serve handler asynchronousHow can i make the Deno.serve handler asynchronous? or like make it so that it can execute asynchronWhy my place.x -= 5 not working?At this part if(moveKey.right.pressed) { finishPostion += 5 quota exceededi hit the free limit tonight and upgraded to pro 20 minutes ago— when do my sites stop erroring withDeploying WASM via Deno Deploy Github ActionsHello, I'm trying to deploy a Leptos project that serves a .wasm bundle for the frontend, and uses Get only the first records with deno kv but reversed orderedI'm using Deno KV to store articles. Generating the ID for the articles: ``` export function generaerror: Uncaught (in promise) SyntaxError: Invalid regular expression flagsAfter Updating my fresh to latest version I got following error ``` deno task start Task start deno third party module repo changeI'm the author of a third party deno module: https://deno.land/x/streamdal_protos@v0.0.126. My comDeno.serve get full path instead of only params and urlI need to get params from an url like this `http://localhost:8000/auth#token_type=Bearer&access_tokeSend custom response inside error event listenerIf I add an event listener for errors in Deno to catch anything my middleware error handler doesn't,assertThrows() limitationsassertThrows() seems to only filter on class name and message. Is there an assert function for checkLSP/VSCode stops workingI'm having issues in my fresh project time to time it stops working and I have to restart it or vscoCan the listeners for messages from Deno Deploy Queues timeout?Can the listeners for messages from Deno Deploy Queues timeout like Vercel serverless functions? Are