> For the complete documentation index, see [llms.txt](https://zer0-2.gitbook.io/type-chef-di/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zer0-2.gitbook.io/type-chef-di/fundamentals/injection/type-injection.md).

# Type injection

The simplest way to resolve classes is the Type resolution \*(resolveByType)

To enabale it when you create the container use param {enableAutoCreate: true}

```typescript
const container = new Container({enableAutoCreate: true});
const service = await container.resolveByType<Service>(Service);
```

{% hint style="info" %}
Make sure all the class dependency has the @Injectable decorator
{% endhint %}

```typescript
import { Container, Injectable } from "type-chef-di";

@Injectable
class SayService {

    public getString() {
        return "pizza";
    }
}

@Injectable
class SayService2 {

    public getString() {
        return "coffee";
    }
}


@Injectable
class Client {
    constructor(private readonly sayService: SayService, private readonly sayService2: SayService2) {
    }

    public say() {
        return `I like ${this.sayService.getString()} and ${this.sayService2.getString()}`;
    }
}

@Injectable
class Service {
    constructor(private readonly client: Client) {
    }

    public check() {
        return `client says: ${this.client.say()}`;
    }
}


async function run() {
    const container = new Container({enableAutoCreate: true});
    const service = await container.resolveByType<Service>(Service); // new Service(new Client(new SayService(), new SayService2()));
    console.log(service.check()); // client says: I like pizza and coffee
}

run();
```


---

# 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://zer0-2.gitbook.io/type-chef-di/fundamentals/injection/type-injection.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.
