Comments (4)
Thank you for the help, @jeffijoe!
from awilix-express.
This works perfectly. Thanks!
from awilix-express.
Yes it is, you register the preconfigured logger in a middleware that runs before your controller code. I do this for the same reason, contextual logging. 😄
from awilix-express.
Here's an example. Include this before your controllers get resolved, and any module that gets resolved in that scope will receive that logger.
app.use((req, res, next) => {
const logger = {
log: (message) => {
console.log(`${req.method} ${req.path}: ${message}`)
}
}
req.container.register({
logger: asValue(logger)
})
next()
})
from awilix-express.
Related Issues (19)
- Add TypeScript Definition file (index.d.ts) HOT 3
- Can we use express-promise-router instead? HOT 2
- Cannot call a class as a function HOT 5
- Injecting dependencies per route instead of when creating controller HOT 4
- Thank you for your contributions HOT 1
- unhandledRejection when returning promises from routes HOT 4
- param decorator
- [question] "@before" middleware with injected dependencies HOT 1
- build: expected targetOrResolver to be a function or class, but got '...' HOT 3
- Resloving dependencies inside @before HOT 1
- Awilix 5.x is out HOT 2
- Cannot convert a Symbol value to a string HOT 4
- Awilix 7.x HOT 8
- Awilix 8.0 peerDependency HOT 1
- Integrate with awilix-router-core HOT 4
- Trying minimal example HOT 1
- Accessing controller instance on before/after middlewares HOT 9
- More descriptive error messages when controller method attempting to be invoked does not exist HOT 1
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 awilix-express.