# ORM Entity Injection

WireBox 2.0.0 supports entity injection via

* [ColdBox ORM Module](https://github.com/coldbox/cbox-cborm) - for use in ColdBox applications
* **Custom ORM Event Handler** - for use in any CFML application

## Custom ORM Event Handler

In order to leverage WireBox for entity injection you will have to create your own custom ORM event handler and activate event handling in the ORM at the `Application.cfc`

```javascript
this.ormSettings = {
    cfclocation="model",
    dbcreate = "update",
    dialect = "MySQLwithInnoDB",
    logSQL = true,
    // Enable event handling
    eventhandling = true,
    // Set the event handler to use, which will be inside our application or the default wirebox one
    eventhandler = "model.ORMEventHandler"
};
```

Then you can create the custom event handler with a custom `postLoad()` function where you will leverage WireBox for DI.

```javascript
component implements="CFIDE.orm.IEventHandler"{

    /**
    * postLoad called by hibernate which in turn announces a coldbox interception: ORMPostLoad
    */
    public void function postLoad(any entity){
        application.wirebox.autowire( 
            target=arguments.entity, 
            targetID="ORMEntity-#getMetadata( arguments.entity ).name#" 
        );
    }

}
```


---

# 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://wirebox.ortusbooks.com/2/advanced-topics/orm-entity-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.
