You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
874 B
29 lines
874 B
import {HTTPKernelModule} from '../HTTPKernelModule'
|
|
import {Inject, Injectable} from '../../../di'
|
|
import {HTTPKernel} from '../HTTPKernel'
|
|
import {Request} from '../../lifecycle/Request'
|
|
import {Bus} from '../../../support/bus'
|
|
|
|
/**
|
|
* HTTP kernel module that creates a request-specific event bus
|
|
* and injects it into the request container.
|
|
*/
|
|
@Injectable()
|
|
export class InjectRequestEventBusHTTPModule extends HTTPKernelModule {
|
|
@Inject()
|
|
protected bus!: Bus
|
|
|
|
public static register(kernel: HTTPKernel): void {
|
|
kernel.register(this).first()
|
|
}
|
|
|
|
public async apply(request: Request): Promise<Request> {
|
|
const requestBus = this.container().makeNew<Bus>(Bus)
|
|
await requestBus.up(false)
|
|
await requestBus.connect(this.bus)
|
|
|
|
request.purge(Bus).registerProducer(Bus, () => requestBus)
|
|
return request
|
|
}
|
|
}
|