Binds injection token to lazy dependency.


import { bindTo, bingLazilyTo } from '@marblejs/core';

Type declaration

bindTo :: ContextToken -> ContextReader -> BoundDependency
bindLazilyTo :: bindTo

The function is responsible for binding context token to ContextReader which can be a fp-ts Reader instance or plain a () => T. The function is producing a lazy binding, which means that, the dependency will be evaluated on it's first call (injection).

bindTo is an alias of bindLazilyTo.


import { reader, bindTo, createServer, createContextToken } from '@marblejs/core';
import { pipe } from 'fp-ts/lib/pipeable';
import * as R from 'fp-ts/lib/Reader';
// create reader
const FooToken = createContextToken<Foo>('FooToken');
const foo = pipe(reader, => {
const otherDependency = ask(OtherToken);
return { ... };
// bind reader to token
const boundDependency = bindTo(FooToken)(foo);