|
9 | 9 |
|
10 | 10 | import { IocContract } from '@adonisjs/fold' |
11 | 11 |
|
12 | | -import { Server } from '../src/Server' |
13 | | -import { Request } from '../src/Request' |
14 | | -import { Response } from '../src/Response' |
15 | | -import { HttpContext } from '../src/HttpContext' |
16 | | -import { MiddlewareStore } from '../src/MiddlewareStore' |
17 | | - |
18 | 12 | export default class HttpServerProvider { |
19 | | - constructor(protected $container: IocContract) {} |
| 13 | + constructor(protected container: IocContract) {} |
20 | 14 |
|
21 | 15 | /** |
22 | 16 | * Register request and response bindings to the container |
23 | 17 | */ |
24 | | - protected $registerRequestResponse() { |
25 | | - this.$container.bind('Adonis/Core/Request', () => Request) |
26 | | - this.$container.bind('Adonis/Core/Response', () => Response) |
| 18 | + protected registerRequestResponse() { |
| 19 | + this.container.singleton('Adonis/Core/Request', () => { |
| 20 | + return require('../src/Request').Request |
| 21 | + }) |
| 22 | + |
| 23 | + this.container.singleton('Adonis/Core/Response', () => { |
| 24 | + return require('../src/Response').Response |
| 25 | + }) |
27 | 26 | } |
28 | 27 |
|
29 | 28 | /** |
30 | 29 | * Registering middleware store to the container |
31 | 30 | */ |
32 | | - protected $registerMiddlewareStore() { |
33 | | - this.$container.bind('Adonis/Core/MiddlewareStore', () => MiddlewareStore) |
| 31 | + protected registerMiddlewareStore() { |
| 32 | + this.container.bind('Adonis/Core/MiddlewareStore', () => { |
| 33 | + return require('../src/MiddlewareStore').MiddlewareStore |
| 34 | + }) |
34 | 35 | } |
35 | 36 |
|
36 | 37 | /** |
37 | 38 | * Registering the HTTP context |
38 | 39 | */ |
39 | | - protected $registerHTTPContext() { |
40 | | - this.$container.bind('Adonis/Core/HttpContext', () => HttpContext) |
| 40 | + protected registerHTTPContext() { |
| 41 | + this.container.bind('Adonis/Core/HttpContext', () => { |
| 42 | + return require('../src/HttpContext').HttpContext |
| 43 | + }) |
41 | 44 | } |
42 | 45 |
|
43 | 46 | /** |
44 | 47 | * Register the HTTP server |
45 | 48 | */ |
46 | | - protected $registerHttpServer() { |
47 | | - this.$container.singleton('Adonis/Core/Server', () => { |
48 | | - const Logger = this.$container.use('Adonis/Core/Logger') |
49 | | - const Profiler = this.$container.use('Adonis/Core/Profiler') |
50 | | - const Config = this.$container.use('Adonis/Core/Config') |
51 | | - const Encryption = this.$container.use('Adonis/Core/Encryption') |
| 49 | + protected registerHttpServer() { |
| 50 | + this.container.singleton('Adonis/Core/Server', () => { |
| 51 | + const { Server } = require('../src/Server') |
52 | 52 |
|
53 | | - const config = Object.assign({ secret: Config.get('app.appKey') }, Config.get('app.http', {})) |
54 | | - return new Server(this.$container, Logger, Profiler, Encryption, config) |
| 53 | + const Logger = this.container.use('Adonis/Core/Logger') |
| 54 | + const Profiler = this.container.use('Adonis/Core/Profiler') |
| 55 | + const Config = this.container.use('Adonis/Core/Config') |
| 56 | + const Encryption = this.container.use('Adonis/Core/Encryption') |
| 57 | + return new Server(this.container, Logger, Profiler, Encryption, Config.get('app.http', {})) |
55 | 58 | }) |
56 | 59 | } |
57 | 60 |
|
58 | 61 | /** |
59 | 62 | * Register the router. The router points to the instance of router used |
60 | 63 | * by the middleware |
61 | 64 | */ |
62 | | - protected $registerRouter() { |
63 | | - this.$container.singleton('Adonis/Core/Route', () => { |
64 | | - return this.$container.use('Adonis/Core/Server').router |
| 65 | + protected registerRouter() { |
| 66 | + this.container.singleton('Adonis/Core/Route', () => { |
| 67 | + return this.container.use('Adonis/Core/Server').router |
65 | 68 | }) |
66 | 69 | } |
67 | 70 |
|
68 | 71 | /** |
69 | 72 | * Registering all bindings |
70 | 73 | */ |
71 | 74 | public register() { |
72 | | - this.$registerRequestResponse() |
73 | | - this.$registerMiddlewareStore() |
74 | | - this.$registerHttpServer() |
75 | | - this.$registerHTTPContext() |
76 | | - this.$registerRouter() |
| 75 | + this.registerRequestResponse() |
| 76 | + this.registerMiddlewareStore() |
| 77 | + this.registerHttpServer() |
| 78 | + this.registerHTTPContext() |
| 79 | + this.registerRouter() |
77 | 80 | } |
78 | 81 | } |
0 commit comments