diff --git a/system/ioc/Injector.cfc b/system/ioc/Injector.cfc index cdfc03330..6d643234f 100644 --- a/system/ioc/Injector.cfc +++ b/system/ioc/Injector.cfc @@ -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 ); diff --git a/system/ioc/config/Binder.cfc b/system/ioc/config/Binder.cfc index 5d141ce74..1eb6e4a3f 100644 --- a/system/ioc/config/Binder.cfc +++ b/system/ioc/config/Binder.cfc @@ -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 * diff --git a/test-harness/config/WireBox.cfc b/test-harness/config/WireBox.cfc index 0a32277f6..b935ec63d 100644 --- a/test-harness/config/WireBox.cfc +++ b/test-harness/config/WireBox.cfc @@ -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 }; diff --git a/tests/specs/integration/WireBoxDSLTests.cfc b/tests/specs/integration/WireBoxTest.cfc similarity index 77% rename from tests/specs/integration/WireBoxDSLTests.cfc rename to tests/specs/integration/WireBoxTest.cfc index 96fa48c19..7a408b473 100644 --- a/tests/specs/integration/WireBoxDSLTests.cfc +++ b/tests/specs/integration/WireBoxTest.cfc @@ -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();