Blog

WireBox version 1.3.0 Released!

Luis Majano November 28, 2011

Spread the word

Luis Majano

November 28, 2011

Spread the word


Share your thoughts

Welcome to another release of WireBox, Dependency Injection and AOP library for ColdFusion, version 1.3.0. This release introduces a few fixes and some incredibly new useful features that will enhance not only your AOP but DI capabilities in your ColdBox and non-ColdBox applications. Also, remember that WireBox can work in ANY ColdFusion framework and not only ColdBox. ColdBox only uses WireBox as its default DI engine for operation.

The following are the enhancements for this version 1.3.0 release:

Setter Injection Improvements

Allow Setter injection to specify argument names or pass positionally. Before you could not specify the name of the argument in a setter method and had to comply to the convention of using the same name as the setter. Now you can define the argument name using the argName argument.

mapPath("my.path.Service)
	.setter(name="CategoryDAO",ref="CategoryDAO", argName="dao");

This would expect the setter signature to be:

function setCategoryDAO(required dao){}

AOP Aspect Improvements

The AOP Method Invocation object now has two new methods: getTargetMapping() and getMethodMetadata(). The getTargetMapping() gives you the mapping object for the target so you can request any metadata, wiring, and construction information. The getMethodMetadata() gives you the actual metadata structure the method that was adviced contains. This is great to determine if the method has a specific annotation or not. You can now build AOP aspects that can determine a target's mapping information and specific method annotations.

Virtual Inheritance

You can now make two CFCs blend together simulating a virtual runtime inheritance. It will grab the target CFC and blend into it all of the virtual inheritance CFC's methods and properties. It will then also create a $super reference in the target and a $superinit() reference. This is a great alternative to real inheritance and allows for runtime mixins to occur. You start off my mapping the base or source CFC from which you will virtually inherit from and then mapping the target CFC and declaring it a virtualInheritance to the base or source CFC:

// Declare base CFC 
map("BaseModel")
.to("model.base.BaseModel"); map("UserService")
.to("model.users.UserService")
.virtualInheritance("BaseModel");

This will grab all methods and properties in the BaseModel CFC and mix them into the UserService, then create a virtual $super scope which will map to an instantiated instance of the BaseModel object that will exist inside of the UserService in case you need to do method overrides much how you do overrides already. This is a great way to change CFCs dynamically at runtime. You are restricted to 1 virtual inheritance per target CFC at this point in time.

Mapping Extra Attributes

You can now store a-la-carte attributes in a specific mapping so it can be retrieved at a later time by either an AOP aspect or Events. This is a great way to store custom metadata about an object so it can be read later for some meaningful purpose. Let's say you want to tag a mapping with a custom type that is not so easily determined from the object instance itself. You don't want to do all kinds of introspection in order to know what object you received in an aspect or an event.


map("MyPlugin") .to("plugins.CustomPlugin") .extraAttributes({ pluginPath = pluginLocation, custom = arguments.custom, module = arguments.module, isPlugin = true });

This mapping declares that an object has some extra attributes that will be stored in the mapping, such as the location, if it is a custom plugin, if it belongs to a module and a marker that determines if it is a plugin or not. This is then incredibly useful when you have an attached listener to WireBox:

function afterInstanceAutowire(event, interceptData){ 	
  var attribs = interceptData.mapping.getExtraAttributes(); 	
  var iData 	= {}; 	 	
  // listen to plugins only 	
  if( structKeyExists(attribs, "isPlugin") ){ 		
    //Fill-up Intercepted MetaData 		
    iData.pluginPath = attribs.pluginPath; 		
    iData.custom 	 = attribs.custom;	 		
    iData.module 	 = attribs.module;		 		
    iData.oPlugin    = interceptData.target; 		 		
    //Fire My Own Custom Interception 		
    instance.interceptorService.processState("afterPluginCreation",iData); 	
    } 
  } 

As you can see from this sample, the extra attributes are incredibly essential, as the listener just sends the target object. It would take lots of introspection and metadata inspections in order for me to determine if the incoming object is my system's plugin or not. However, with the extra attributes, it is just a snap!

Runtime Mixins()

You can now use our spanking new mixins() binder method to define that a mapping should be mixed in with one or more set of UDF templates. It will then at runtime inject all the methods in those templates and mix them into the target object as public methods.

// map with mixins 
map("MyService") 	
  .to("model.UserService") 	
  .mixins("/helpers/base");  
  
// map with mixins as list 
map("MyService") 	
  .to("model.UserService") 	
  .mixins("/helpers/base, /helpers/model");  

// map with mixins as array 
map("MyService") 	
  .to("model.UserService") 	
  .mixins( ["/helpers/base", "/helpers/model"] ); 

This will grab all the methods in the base.cfm and model.cfm templates and inject them into the target mapping as public methods. Awesome right?

Expanded ColdBox DSL

  • coldbox:setting:mySetting@module : You can now inject easily a module setting by using the @module directive.
  • coldbox:moduleSettings:{module} : You can now inject the entire module settings structure
  • coldbox:moduleConfig:{module} : You can now inject the entire module configuration structure

Download Now!

So if you are using WireBox standalone, get the update or if you are using ColdBox, then just upgrade to the latest ColdBox build, 3.5.0 BETA

Add Your Comment

Recent Entries

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Unfortunately, we often hear this message from clients who thought it would never happen to them... until it did. Some believed they could delay the expense of Implementing ColdFusion security best practices for one year, while others were tempted to put it off for just a few months. However, in today's rapidly evolving digital landscape, the security of web applications, including ColdFusio...

Cristobal Escobar
Cristobal Escobar
April 16, 2024
Ortus March Newsletter

Ortus March Newsletter

Welcome to Ortus Solutions’ monthly roundup, where we're thrilled to showcase cutting-edge advancements, product updates, and exciting events! Join us as we delve into the latest innovations shaping the future of technology.

Maria Jose Herrera
Maria Jose Herrera
April 01, 2024
Into the Box 2024 Last Early Bird Days!

Into the Box 2024 Last Early Bird Days!

Time is ticking, with less than 60 days remaining until the excitement of Into the Box 2024 unfolds! Don't let this golden opportunity slip away; our exclusive Early Bird Pricing is here for a limited time only, available until March 31st. Why wait? Secure your seat now and take advantage of this steal!

Maria Jose Herrera
Maria Jose Herrera
March 20, 2024