LogoLogo
ChangelogGitHubTwitterGitter
v4.x
v4.x
  • Marble.js
  • Getting started
    • Installation
    • Quick setup
  • HTTP
    • Effects
    • Middlewares
    • Routing
    • Errors
    • Output
    • Context
    • Advanced
      • Logging
      • Validation
      • Server Events
      • Streaming
      • Continuous mode
  • Messaging
    • Core concepts
      • Events
      • Effects
    • Microservices
      • AMQP (RabbitMQ)
      • Redis Pub/Sub
    • CQRS
    • WebSockets
  • Testing
    • HTTP routes testing
  • Other
    • How does it glue together?
    • Migration guides
      • Migration from version 3.x
      • Migration from version 2.x
      • Migration from version 1.x
    • API reference
      • @marblejs/core
        • bindTo
        • bindEagerlyTo
        • createEvent
        • createContextToken
        • operator: matchEvent
        • operator: use
        • operator: act
      • @marblejs/http
        • httpListener
        • r.pipe
        • combineRoutes
        • createServer
      • @marblejs/messaging
        • eventBus
        • messagingClient
        • createMicroservice
        • reply
      • @marblejs/websockets
        • webSocketListener
        • operator: broadcast
        • operator: mapToServer
      • @marblejs/middleware-multipart
      • @marblejs/middleware-cors
      • @marblejs/middleware-io
      • @marblejs/middleware-logger
      • @marblejs/middleware-body
      • @marblejs-contrib/middleware-jwt
        • Token signing
      • @marblejs-contrib/middleware-joi
    • Style Guide
    • FAQ
Powered by GitBook
On this page
  • Importing
  • Type declaration
  • Example
  1. Other
  2. API reference
  3. @marblejs/core

bindTo

Binds injection token to lazy dependency.

Importing

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.

Example

import { reader, bindTo, createContextToken } from '@marblejs/core';
import { createServer } from '@marblejs/http';
import { pipe } from 'fp-ts/lib/function';
import * as R from 'fp-ts/lib/Reader';

// create reader

const FooToken = createContextToken<Foo>('FooToken');

const foo = pipe(reader, R.map(ask => {
  const otherDependency = ask(OtherToken);
  
  return { ... };
});


// bind reader to token

const boundDependency = bindTo(FooToken)(foo);

Previous@marblejs/coreNextbindEagerlyTo

Last updated 3 years ago