Skip to content

Commit

Permalink
WIREBOX-61 #resolve
Browse files Browse the repository at this point in the history
Make wirebox.system.aop.Mixer listener load automatically if any aspects are defined/mapped
  • Loading branch information
lmajano committed Oct 17, 2023
1 parent 429613d commit 46007cd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
17 changes: 15 additions & 2 deletions system/ioc/Injector.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1501,18 +1501,31 @@ component serializable="false" accessors="true" {
* Register all the configured listeners in the configuration file
*/
private Injector function registerListeners(){
var aopMixerAdded = false;
for ( var thisListener in variables.binder.getListeners() ) {
if( thisListener.class == "coldbox.system.aop.Mixer" ){
aopMixerAdded = true;
}
registerListener( thisListener );
}
// If we have any aspects defined but no mixer, auto-add it
if( !aopMixerAdded && variables.binder.hasAspects() ){
variables.log.info( "AOP aspects detected but no Mixer listener found, auto-adding it with defaults..." );
registerListener( {
class: "coldbox.system.aop.Mixer",
name: "aopMixer"
} );
}
return this;
}

/**
* Register all the configured listeners in the configuration file
*
* @listener The listener to register
* @listener The listener struct to register: { class, name, properties }
*/
public Injector function registerListener( required listener ){
public Injector function registerListener( required struct listener ){
param arguments.listener.properties = {};
try {
// create it
var thisListener = createObject( "component", listener.class );
Expand Down
11 changes: 11 additions & 0 deletions system/ioc/config/Binder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,17 @@ component accessors="true" {
return this;
}

/**
* Verify if we have aspects defined in this binder
*
* @return True if we have aspects, false if not
*/
boolean function hasAspects(){
return mappings.some( (key, mapping) => {
return arguments.mapping.isAspect();
} );
}

/**
* Create a new matcher class for usage in class or method matching
*
Expand Down
2 changes: 1 addition & 1 deletion test-harness/config/WireBox.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// Parent Injector to assign to the configured injector, this must be an object reference
parentInjector : "",
// Register all event listeners here, they are created in the specified order
listeners : [ { class : "coldbox.system.aop.Mixer" } ],
listeners : [ ],
// Enable transient injection cache
transientInjectionCache : true
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ component extends="tests.resources.BaseIntegrationTest" {
/*********************************** BDD SUITES ***********************************/

function run(){


story( "Make AOP mixer auto-load if any aspects are defined", function(){
given( "1 or more aspects defined", function(){
then( "the AOP mixer must load", function(){
var mixer = controller.getInterceptorService().getInterceptionStates();
expect( mixer ).toHaveKey( "afterInstanceAutowire" );
expect( mixer.afterInstanceAutowire.getPool().containsKey( "aopmixer") ).toBeTrue();
});
});
});

describe( "WireBox custom DSL", function(){
beforeEach( function( currentSpec ){
setup();
Expand Down

0 comments on commit 46007cd

Please sign in to comment.