Skip to content

Commit 86c3e8e

Browse files
committed
fix: 当没有controller的时候不走ioc
1 parent 6a80eb8 commit 86c3e8e

File tree

2 files changed

+52
-29
lines changed

2 files changed

+52
-29
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22
# 0.3.0 (2019-12-15)
33

44

5+
### Bug Fixes
6+
7+
* delete dts/ and lib/ ([5e31825](https://github.com/hubvue/kim/commit/5e31825))
8+
* injects empty ([0edb3f4](https://github.com/hubvue/kim/commit/0edb3f4))
9+
* 删除loader文件 ([6a80eb8](https://github.com/hubvue/kim/commit/6a80eb8))
10+
11+
12+
### Features
13+
14+
* add all route ([7a2c07f](https://github.com/hubvue/kim/commit/7a2c07f))
15+
* add BaseController, all Controller extends BaseController. shield route params, ctx and next binding Controller this ([7c3a890](https://github.com/hubvue/kim/commit/7c3a890))
16+
* add headers、req、res、params、cookie decotator ([50960c5](https://github.com/hubvue/kim/commit/50960c5))
17+
* add ioc&http-decorator ([e07a689](https://github.com/hubvue/kim/commit/e07a689))
18+
* add koa router ([6229e81](https://github.com/hubvue/kim/commit/6229e81))
19+
* init koa runtime ([72211b8](https://github.com/hubvue/kim/commit/72211b8))
20+
21+
22+
23+
<a name="0.3.0"></a>
24+
# 0.3.0 (2019-12-15)
25+
26+
527
### Bug Fixes
628

729
* delete dts/ and lib/ ([5e31825](https://github.com/hubvue/kim/commit/5e31825))

src/core/index.ts

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,39 @@ export const createApplication = (
2525
META_CONTROLLER,
2626
CONTROLLER_POLL
2727
)
28-
29-
for (let controllerMeta of controllerPoll) {
30-
const { path, constructor } = controllerMeta
31-
const controller: any = new constructor()
32-
if (!('_isExtends' in controller)) {
33-
throw new Error(`class ${constructor.name} not extends BaseController`)
34-
}
35-
const injects: Array<InjectInterface> = Reflect.getMetadata(
36-
META_INJECT,
37-
controller
38-
)
39-
if (injects) {
40-
for (let inject of injects) {
41-
const { propertyKey, tag } = inject
42-
const injectable: new () => {} = instancePoll.get(tag)
43-
if (injectable) {
44-
Object.defineProperty(controller, propertyKey, {
45-
value: new injectable(),
46-
writable: false,
47-
configurable: false,
48-
enumerable: true
49-
})
50-
} else {
51-
throw new Error(`not ${String(tag)} model is injectable`)
28+
if (controllerPoll) {
29+
for (let controllerMeta of controllerPoll) {
30+
const { path, constructor } = controllerMeta
31+
const controller: any = new constructor()
32+
if (!('_isExtends' in controller)) {
33+
throw new Error(`class ${constructor.name} not extends BaseController`)
34+
}
35+
const injects: Array<InjectInterface> = Reflect.getMetadata(
36+
META_INJECT,
37+
controller
38+
)
39+
if (injects) {
40+
for (let inject of injects) {
41+
const { propertyKey, tag } = inject
42+
const injectable: new () => {} = instancePoll.get(tag)
43+
if (injectable) {
44+
Object.defineProperty(controller, propertyKey, {
45+
value: new injectable(),
46+
writable: false,
47+
configurable: false,
48+
enumerable: true
49+
})
50+
} else {
51+
throw new Error(`not ${String(tag)} model is injectable`)
52+
}
5253
}
5354
}
54-
}
5555

56-
controllers.add({
57-
controller,
58-
path
59-
})
56+
controllers.add({
57+
controller,
58+
path
59+
})
60+
}
6061
}
6162
const app: Koa = KoaRuntime(controllers, options)
6263
return app

0 commit comments

Comments
 (0)