> For the complete documentation index, see [llms.txt](https://dscheglov.gitbook.io/true-di/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dscheglov.gitbook.io/true-di/recipes/creating-all-items.md).

# Creating All Items

As usually you don't need to create all items at once, but it is quit convinient way to check if all items could be created and container doesn't have cyclic creation dependencies.

```typescript
describe('myContainer', () => {
  it('creates all items', () => {
    expect({ ...container }).toEqual(container);
  });
});
```

As you can see all items could be instantiated by using spread or rest operators:

```typescript
const items = { ...container }; // using spread operator
// or
const { ...items } = container; // using rest and destructuring
```

However such aproach doesn't work if container has some non-enumerable fields:

```typescript
type Container = {
  x: number,
  y: number,
  z: number,
};

const container = diContainer<Container>(Object.create(null, {
  x: { value: () => 1, enumerable: true },
  y: { value: () => 2, enumerable: true },
  z: { value: () => 3, enumerable: false },
}));

const items = { ...container };

console.log({ z: items.z });
// prints: { z: undefined }

console.log({
    isXReady: isReady(container, 'x'),
    isYReady: isReady(container, 'y'),
    isZReady: isReady(container, 'z'),
});

// prints: { isXReady: true, isYReady: true, isZReady: false }
```

To create all items including bound to non-enumerable fields use [`prepareAll`](/true-di/core/prepare-all.md) function:

```typescript
const container = diContainer<Container>(Object.create(null, {
  x: { value: () => 1, enumerable: true },
  y: { value: () => 2, enumerable: true },
  z: { value: () => 3, enumerable: false },
}));

const items = prepareAll(container);

console.log({ z: items.z });
// prints: { z: 3 }

console.log({
    isXReady: isReady(container, 'x'),
    isYReady: isReady(container, 'y'),
    isZReady: isReady(container, 'z'),
});

// prints: { isXReady: true, isYReady: true, isZReady: true }
```

It is suggested to use [`prepareAll`](/true-di/core/prepare-all.md) function raither then spread/rest operators because:

1. it is more explicitly creates all items (explicit is better then implicit)
2. it is most reliable way to create all items


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://dscheglov.gitbook.io/true-di/recipes/creating-all-items.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.
