CBWIRE
v4.x
v4.x
  • Introduction
  • How It Works
  • Getting Started
  • Configuration
  • Releases
    • What's New With 4.1
    • What's New With 4.0
    • What's New With 3.2
    • What's New With 3.1
    • What's New With 3.0
    • What's New With 2.2
    • What's New With 2.1
    • What's New With 2.0
  • Resources
  • Upgrading from CBWIRE 3.x
  • Upgrading from CBWIRE 2.x
  • CBWIRE CLI
  • The Essentials
    • Components
    • Templates
    • Data Properties
    • Computed Properties
    • Data Binding
    • Actions
    • Events
    • Nesting Components
    • Lifecycle Methods
    • JavaScript
    • Testing
  • Features
    • Single-file Components
    • Alpine.js
    • Lazy Loading
    • Form Validation
    • File Uploads
    • Query String
    • Redirecting
    • WireBox
  • Template Directives
    • wire:click
    • wire:confirm
    • wire:dirty
    • wire:ignore
    • wire:init
    • wire:key
    • wire:loading
    • wire:model
    • wire:navigate
    • wire:offline
    • wire:poll
    • wire:stream
    • wire:submit
    • wire:transition
  • Advanced
    • Troubleshooting
Powered by GitBook
On this page
  • Overview
  • Getting Instances
  • Documentation

Was this helpful?

Export as PDF
  1. Features

WireBox

PreviousRedirectingNextwire:click

Last updated 7 months ago

Was this helpful?

Overview

You can access any dependencies your component may have using , ColdBox's robust dependency injection framework.

This is a great way to keep your business logic out of your components.

You can achieve this by defining a CFC property in your component and using inject.

property name="postService" inject="PostService";
// ./models/PostService.cfc
component singleton {
    function getAll() {
        return queryExecute( "select * from posts" );
    }
}
// ./wires/Posts.cfc
component extends="cbwire.models.Component" {
    property name="postService" inject="PostService";
    function allPosts() {
        return postService.getAll();
    }
}
<!--- ./wires/posts.cfm --->
<cfoutput>
    <div>
        <h1>Posts</h1>
        <cfloop array="#allPosts()#" index="post">
            <div wire:key="post-#post.id#">
                <h2>#post.title#</h2>
            </div>
        </cfloop>
    </div>
</cfoutput>

CBWIRE uses WireBox internally to load your components. Any lifecycle methods fired by WireBox are available to you.

Getting Instances

You can use getInstance() to access a dependency from within your actions.

// ./wires/Posts.cfc
component extends="cbwire.models.Component" {
    function allPosts() {
        var postService = getInstance( "PostService" );
        return postService.getAll();
    }
}

Here is the method signature for getInstance():

/**
 * Get a instance object from WireBox
 *
 * @name The mapping name or CFC path or DSL to retrieve
 * @initArguments The constructor structure of arguments to passthrough when initializing the instance
 * @dsl The DSL string to use to retrieve an instance
 *
 * @return The requested instance
 */
function getInstance( name, initArguments={}, dsl )

Documentation

Learn about the full capabilities of WireBox at .

WireBox
https://wirebox.ortusbooks.com/