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

jeffijoe / awilix-koa / 10797816040

10 Sep 2024 05:42PM UTC coverage: 90.278% (-9.7%) from 100.0%
10797816040

push

github

web-flow
Merge pull request #69 from dlgoodchild/master

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 16 new or added lines in 3 files covered. (56.25%)

65 of 72 relevant lines covered (90.28%)

10.22 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 attachContainerMiddleware(
×
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