Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Itb2018 wire box basics

66 views

Published on

Brad Wood

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Itb2018 wire box basics

  1. 1. WireBox Basics Dead Simple DI Brad Wood @bdw429s
  2. 2. WireBox, friend of CFCs ● Part of ColdBox ● Also standalone! ● Helps you create, persist, and manage the CFCs in your app
  3. 3. OO Overview ● Encapsulation ● Re-use ● Separation of data of behavior ● Inherited behavior between objects
  4. 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. 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. 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. 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. 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. 9. Object Factory ● When we want a CFC instance, we ask WireBox ● WireBox handles creation for us myService = getInstance( ‘myService’ ); myService.doSomething();
  10. 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. 11. ● One CFC instance per session ● You don’t have to actually touch the session scope component scope=”session” { } Session Persistence
  12. 12. ● When one CFC needs another ● Use cfproperty to declare the dependency component { property name=”myFoo” inject=”FooService”; } Dependencies
  13. 13. ● Generic ad-hoc way to get CFC instances ● In ColdBox, getInstance() exists everywhere ● Outside of ColdBox, wirebox.getInstance() application.wirebox.getInstance( ‘FooBar’ ); getInstance()

×