# bindTo

### **Importing** <a href="#importing" id="importing"></a>

```typescript
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`.&#x20;

### **Example**

```typescript
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);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://marblejs.gitbook.io/docs/other/api-reference/core/bind.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
