UNPKG

@chubbyts/chubbyts-framework

Version:

A minimal, highly performant middleware PSR-15 inspired function based microframework built with as little complexity as possible, aimed primarily at those developers who want to understand all the vendors they use.

21 lines (20 loc) 816 B
/** * ```ts * import type { Container } from '@chubbyts/chubbyts-dic-types/dist/container'; * import { createContainer } from '@chubbyts/chubbyts-dic/dist/container'; * import type { Handler } from '@chubbyts/chubbyts-http-types/dist/handler'; * import type { Logger } from 'some-logger/dist/logger'; * import { createLazyHandler } from '@chubbyts/chubbyts-framework/dist/handler/lazy-handler'; * * const container: Container = createContainer(); * * container.set('handlerServiceId', (container: Container): Handler => { * return createMyHandler(container.get<Logger>('logger')); * }); * * const handler: Handler = createLazyHandler(container, 'handlerServiceId'); * ``` */ export const createLazyHandler = (container, id) => { return async (request) => (await container.get(id))(request); };