Comments (4)
@syzer I have thoughts whether DI should remain in the handly developer toolbox in 2017. I saw 3-4 huge NG applications in the last 2 years and none really needed DI.
can you exemplify a typical scenario in backend app that is well modularized into services where one need a *framework to make the decision which provider to instantiate?
Disclaimer: I used a lot DI framework in the past
from nodebestpractices.
Cool topic. Managing in terms of testing only? management can encompass the entire NPM domain, we should narrow this scope
from nodebestpractices.
@i0natan its not only about testing.
Most frameworks have already DI injection micro framework in them.
So that would be very framework dependent
Personally I like how (JSR330) is doing
@Inject private Logger logger;
Angular 2 does very similar annotation based approach.
Other good Idea is using registry with all dependencies lazy resolutions,
via (anonymous functions/arrows) or getters get() { .. }
All above allow hot code loading/push on servers and frontends.
(And easy mocking for test.)
from nodebestpractices.
Hi!
I think DI is very important for testing, code purity (as in controllable side-effects) and functions (units) that define their dependencies up-front.
I found it is hard to educate regarding this topic, as it mostly produces only more code before it really gets useful in mid to large scale applications. (large scale speaking of ~10000 LoC). Even in smaller applications it can be of great help to make even side-effectful functions to work in unit tests.
I think we can still put it as a best practice with maybe a few concrete hints or libs.
Whereas I myself has experienced that DI can be done properly and easily without additional libraries.
Examples:
Simple:
const random = (Math, max) => Math.random() * max
Complex:
complex module requiring different other modules and libs:
const startServer = dependencies => {
const app = dependencies.express()
app.listen(dependencies.env.PORT, () => {
dependencies.log(`server started on ${dependencies.env.PORT}`)
})
return app
}
const express = require('express')
startServer({ express, log: console.log, env: process.env })
Good alternative names for dependencies
is ctx
, context
or options
.
Mixing options and dependencies is okay for me IMHO. One can also separate these if needed.
from nodebestpractices.
Related Issues (20)
- Easy to translate advice HOT 1
- Translations status HOT 1
- Bonnes pratiques nodejs
- Arabic Translation
- Node practice 1
- Should include Corepack in our recommendation? HOT 5
- Bootstraping nodejs container may be misleading
- Node
- Node js fullstack HOT 4
- Wrong example HOT 2
- Broken link to env-var
- Nextjs as main framework? HOT 2
- Another comment regarding "1.1 Structure your solutions by business components" HOT 1
- Italian Translation
- The backend-testing-checklist.png file is missing. HOT 3
- Hinglish Translation HOT 1
- Кнас
- Dead link for safe-regex
- Mi006
- Is using cache for npm install in docker safe?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodebestpractices.