4. Types of objects
● Transient
○ var order = new Order();
● Singleton
○ application.myService = new myService();
● Session-scoped
○ session.user = new User();
● Cache-scoped
○ myCache.set( new featuredContent() );
5. Objects are needy
● They need other objects
● They need app settings like datasources, etc
● A large app can have hundreds of interdependent objects
● This creates boilerplate and complicates your code
6. WireBox is here to simplify your life
● Creates objects
● Managed persistence
● Manages Dependencies
● Easily configurable with simple conventions and
annotations
● No XML, no huge config files!
7. Install WireBox
● ColdBox: Nothing to do here
○ Drop your CFCs in /models
○ Configure it with /config/WireBox.cfc
● Standalone: “install wirebox”
○ new wirebox.system.Injector();
○ application.wirebox.getInstance( ‘foobar’ );
8. Map directory
● Ask WireBox to recursively scan a folder
● Any CFCs found are registered with their name
● You can ask for these CFCs by name now
mapDirectory( ‘/models’ );
9. Object Factory
● When we want a CFC instance, we ask WireBox
● WireBox handles creation for us
myService = getInstance( ‘myService’ );
myService.doSomething();
10. ● Only need one instance of a CFC
● No overhead of creation every time
● Make sure your code is thread safe
component singleton {
}
Singleton Persistence
11. ● One CFC instance per session
● You don’t have to actually touch the session scope
component scope=”session” {
}
Session Persistence
12. ● When one CFC needs another
● Use cfproperty to declare the dependency
component {
property name=”myFoo” inject=”FooService”;
}
Dependencies
13. ● Generic ad-hoc way to get CFC instances
● In ColdBox, getInstance() exists everywhere
● Outside of ColdBox, wirebox.getInstance()
application.wirebox.getInstance( ‘FooBar’ );
getInstance()