> For the complete documentation index, see [llms.txt](https://wirebox.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wirebox.ortusbooks.com/usage/injection-dsl/bytype-namespace.md).

# ByType Namespace

The `bytype` namespace resolves a dependency by the **native type** declared on the property or constructor/setter argument, instead of by name. WireBox reads the type off the property/argument declaration itself and asks the injector to build/locate a mapping whose name matches that type - so the type you declare doubles as the lookup key.

This is handy when you want the argument/property name to be whatever reads best in your code, while the actual dependency to inject is driven purely by its class name/mapping alias.

### 1st Level DSL

| DSL      | Description                                                                                                                     |
| -------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `bytype` | Look up and inject a mapped instance using the property, constructor argument, or setter's declared `type` as the mapping name. |

{% hint style="info" %}
The `type` isn't part of the `inject` value itself - it's the normal `type` attribute/type declaration you already put on the property or argument. WireBox simply reads it when `inject="bytype"` is used, and if no instance can be found matching that type it falls through like any other unresolved dependency (throwing unless `required=false`).
{% endhint %}

{% tabs %}
{% tab title="BoxLang" %}

```js
// Property injection: WireBox will look up a mapping named "UserService"
property name="userService" type="UserService" inject="bytype";

// Constructor injection: annotate the argument with @inject bytype and give it a real type
class {

    /**
     * @userService.inject bytype
     */
    function init( required UserService userService ){
        variables.userService = arguments.userService
        return this
    }

}
```

{% endtab %}

{% tab title="CFML" %}

```cfscript
// Property injection: WireBox will look up a mapping named "UserService"
property name="userService" type="UserService" inject="bytype";

// Constructor injection: annotate the argument with @inject bytype and give it a real type
component {

    /**
     * @userService.inject bytype
     */
    function init( required UserService userService ){
        variables.userService = arguments.userService;
        return this;
    }

}
```

{% endtab %}
{% endtabs %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://wirebox.ortusbooks.com/usage/injection-dsl/bytype-namespace.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
