For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

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).

// 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
    }

}
// 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;
    }

}

Last updated

Was this helpful?