WireBox : Dependency Injection & AOP
7.x
7.x
  • Introduction
    • Contributing Guide
    • Release History
      • What's New With 7.2.0
      • What's New With 7.1.0
      • What's New With 7.0.0
    • Upgrading to WireBox 7
    • About This Book
      • Author
  • Getting Started
    • Overview
    • Installing WireBox
    • Getting Jiggy Wit It!
      • Instance Creations
      • Binder Introduction
      • Scoping
      • Eager Init
      • How WireBox Resolves Dependencies
    • Migrating From ColdSpring
  • Configuration
    • Configuring WireBox
      • Binder Configuration Properties
      • Binder Environment Properties
      • ColdBox Enhanced Binder
      • Types & Scopes
      • Data Configuration Settings
      • Programmatic Configuration
    • Mapping DSL
      • Mapping Initiators
      • Mapping Destinations
      • MapDirectory() Influence & Filters
      • Persistence DSL
      • Dependencies DSL
        • Mapping Extra Attributes
      • Mapping DSL Examples
      • Influence Instances at Runtime
      • Processing Mappings
    • Component Annotations
      • Persistence Annotations
      • CacheBox Annotations
    • Parent Object Definitions
  • Usage
    • WireBox Injector
      • Injector Constructor Arguments
      • Injection Idioms
      • Common Methods
    • Injection DSL
      • ColdBox Namespace
      • CacheBox Namespace
      • EntityService Namespace
      • Executor Namespace
      • Java Namespace
      • LogBox Namespace
      • Models Namespace
      • Provider Namespace
      • WireBox Namespace
    • WireBox Delegators
    • WireBox Event Model
      • WireBox Events
      • WireBox Listeners
        • ColdBox Mode Listener
        • Standalone Mode Listener
  • Advanced Topics
    • Child Injectors
    • Lazy Properties
    • Object Persistence & Thread Safety
    • ORM Entity Injection
    • Providers
      • Custom Providers
      • toProvider() closures
      • Virtual Provider Injection DSL
      • Virtual Provider Mapping
      • Virtual Provider Lookup Methods
      • Provider onMissingMethod Proxy
      • Scope Widening Injection
    • Property Observers
    • Runtime Mixins()
    • WireBox Object Populator
      • populateFromXML
      • populateFromQuery
      • populateFromStruct
      • populateFromQueryWithPrefix
      • populateFromJSON
    • Virtual Inheritance
  • Extending WireBox
    • Custom DSL
      • The DSL Builder Interface
      • Registering a Custom DSL
    • Custom Scopes
      • The Scope Interface
      • Scoping Process
      • Registering a Custom Scope
    • WireBox Injector Interface
  • Aspect Oriented Programming
    • AOP Intro
      • Overview
        • AOP Vocabulary
      • Activate The AOP Listener
      • Create Your Aspect
        • MethodInvocation Useful Methods
        • MethodLogger Aspect
      • Aspect Registration
      • Aspect Binding
      • Auto Aspect Binding
        • ClassMatcher Annotation DSL
        • MethodMatcher Annotation DSL
      • Included Aspects
        • CFTransaction
        • HibernateTransaction
        • MethodLogger
      • Summary
Powered by GitBook
On this page
  • Implicit Builder
  • Explicit Builder
  • No Locking

Was this helpful?

Edit on GitHub
Export as PDF
  1. Advanced Topics

Lazy Properties

Wanna be lazy?

WireBox supports the concept of marking properties in your components as lazy. This will allow the property to be constructed ONCE when requested ONLY (lazy loaded). This way, you can take advantage of the construction of the property being lazy-loaded for you.

Please note that this is different than providers since in this case, you provide the function that will build the property and it can be anything you want.

Internally, we will generate a getter method for you that will make sure to construct your property via a builder function you will provide, lock the request (by default), store it in the variables scope, and return it to you.

Note: With lazy properties, you must use the getter only to retrieve the property ONLY!

component{
	
	// Lazy property: Constructed by convention via the buildUtil() method
	property name="util" lazy;

	/**
	 * Build a util object lazyily.
	 * The first time you call it, it will lock, build it, and store it by convention as 'variables.util'
	 */
	function buildUtil(){
		return new coldbox.system.core.util.Util();
	}

}

Implicit Builder

When you tag a property as lazy, we will look for a method using the following pattern by convention:

function build{propertyName}(){}

We will lock, call the builder, store the property and return it.

Explicit Builder

If you want to use ANY method in your CFC to build the property, then use the value of the lazy annotation to point to the public or private method that will build your property:

component{
	
	property name="data" lazy="constructData";

	function constructData(){
		return dataservice.buildStrongData();
	}

}

No Locking

By default, WireBox will lock the construction of the property. If you do not want the locking to occur, use the LazyNoLock attribute. Just as before, if you don’t have a value for the annotation, we will look for a build{propertyName} function, or if it has a value, we will use that as the name of the builder function.

component{
	
	property name="util" lazyNoLock;
	property name="util" lazyNoLock="constructUtil";

	/**
	 * Build a util object lazyily.
	 * The first time you call it, build it, and store it by convention as 'variables.util'
	 */
	function buildUtil(){
		return new coldbox.system.core.util.Util();
	}

	function constructUtil(){
		return new coldbox.system.core.util.Util();
	}

}
PreviousChild InjectorsNextObject Persistence & Thread Safety

Last updated 2 years ago

Was this helpful?