# Virtual Provider Injection DSL

You can inject automatic object providers by using the provider injection DSL namespace. This will inject a WireBox provider class (`wirebox.system.ioc.Provider`) that follows our [Provider pattern](http://en.wikipedia.org/wiki/Provider_model) with one method on it: `get()` that will provide you with the requested mapped object.

The difference between custom providers here is that WireBox will create a virtual provider object for you dynamically at runtime, configure it to retrieve a specific type of mapping and then use that for you. The **provider** namespace will take everything after it and evaluate it as either a named mapping or a full injection DSL string.

For example, `inject="provider:MyService"` will inject a provider of `MyService` objects, so it will look for a `MyService` ID in the binder. However, you can also get mega funky and do this: `inject="provider:logbox:logger:{this}"` and WireBox will create a provider of `logbox:logger:{this}`.

> **Caution** Remember that the value of the provider can be a simple ID or a full injection DSL.

```javascript
// use the provider DSL namespace on a property
property name="searchCriteria" inject="provider:requestCriteria";

// use the provider DSL namespace on a constructor argument
function init(coolObjectProvider inject="provider:HardToConstructObject"){
    variables.coolObjectProvider = arguments.coolObjectProvider;
    return this;
}

// To use it
searchCriteria.get().getCriteria();
coolObjectProvider.get().executeSomeMethod();
```

\
&#x20;That's it! You basically use the `provider:{mapping}` injection DSL to tell a property, setter or argument that you want a provider object instead of the real deal. This will allow you to delay construction of such an object or avoid the nasty pitfall of scope widening injection.


---

# 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/advanced-topics/providers/virtual-provider-injection-dsl.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.
