• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jeffijoe / awilix-koa / 10793695185

10 Sep 2024 01:39PM UTC coverage: 91.549%. First build
10793695185

Pull #69

github

web-flow
Merge 22aa0c725 into 59721e53d
Pull Request #69: feat: allow having controllers with a singleton lifetime and permit usage without scoped containers in koa state

21 of 28 branches covered (75.0%)

9 of 15 new or added lines in 3 files covered. (60.0%)

65 of 71 relevant lines covered (91.55%)

10.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.5
/src/scope-per-request.ts
1
import { AwilixContainer } from 'awilix'
2

3
/**
4
 * Koa middleware factory that will create and attach
5
 * a scope onto a content.
6
 *
7
 * @param  {AwilixContainer} container
8
 * @return {Function}
9
 */
10
export function scopePerRequest(container: AwilixContainer) {
8✔
11
  return function scopePerRequestMiddleware(
8✔
12
    ctx: any,
13
    next: import('koa').Next,
14
  ) {
15
    ctx.state.container = container.createScope()
24✔
16
    return next()
24✔
17
  }
18
}
19

20
/**
21
 * Koa middleware factory that will simply attach the container
22
 * to the context (ctx) state, with no additional scoping.
23
 *
24
 * You should only use one of either scopePerRequest or attachContainer.
25
 *
26
 * @param  {AwilixContainer} container
27
 * @return {Function}
28
 */
29
export function attachContainer(container: AwilixContainer) {
8✔
NEW
30
  return function scopePerRequestMiddleware(
×
31
    ctx: any,
32
    next: import('koa').Next,
33
  ) {
NEW
34
    ctx.state.container = container
×
NEW
35
    return next()
×
36
  }
37
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc