DEV Community

Cover image for Dependency Injection With Deno 1.29.1 (Node Compatibility)
bronifty
bronifty

Posted on

2

Dependency Injection With Deno 1.29.1 (Node Compatibility)

Clean Architecture With Deno

Youtube Link
Github Repo

Leveraging Uncle Bob principles of Clean Code and Architecture to design some inversion of control and dependency injection in Deno's newest version with Node compatibility. The source uses classes instead of functions, because classes are cleaner (they house all properties and methods with access using a dot operator, instead of fishing around files and gathering exports).

To run this:

-make sure latest version of deno is installed
(deno 1.29.1) with npm: compatibility

deno run src/server.ts --allow-all
Enter fullscreen mode Exit fullscreen mode
  • answer 'y' to all prompts

There are 2 endpoints

1 GET /
2 POST /users -d {name, age}

curl localhost:8080/

curl -X POST -H "Content-Type: application/json" \
 -d '{"name":"abc","age": 123}' \
 localhost:8080/users
Enter fullscreen mode Exit fullscreen mode

Note

  • I did have an error in the node code because the post route kept creating duplicates despite the logic checking for that. For some reason, deno version runs much quicker and it doesn't have the bug.

Todo

  • add some tests

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (2)

Collapse
 
reggi profile image
Tea Reggi •

Interesting use of a constructor and declaring this methods within it. I like the idea of dependency injection like this. I do just feel like the database can be passed into a function directly like this. I've been trying to tinker with a simpler routing system that works with Request and Response and URLPattern.

gist.github.com/reggi/6bb464619468...

Collapse
 
bronifty profile image
bronifty •

Will check

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more