How do I configure my wirebox so it registers forg...
# box-products
d
How do I configure my wirebox so it registers forgebox modules installed in my application root modules folder? My config file is located here: /WireboxConfig.cfc and in the configure method I have this:
binder.mapDirectory('modules')
and my CFC is attempting to get an instance of HyperBuilder with the property dsl
property name="hyper" inject="HyperBuilder@hyper";
but I get this error:
Copy code
The target 'DuoClient' requested a missing dependency with a Name of 'hyper' and DSL of 'HyperBuilder@hyper' {"javaCast":null,"ref":null,"scope":"variables","required":true,"value":null,"dsl":"HyperBuilder@hyper","type":"any","argName":"","name":"hyper"}
The error occurred on line wirebox\system\ioc\Builder.cfc:621
e
Sounds like you're recreating ColdBox’s
ModuleService
. With the code you've shared, you are very likely registering the CFCs inside Hyper. The difference is ColdBox’s
ModuleService
adds a suffix or namespace of
@#moduleName#
. So, you can either use the module name without the namespace (i.e.
HyperBuilder
), loop over the directories in
modules
and apply the suffix yourself when calling
mapDirectory
(which is what ColdBox’s
ModuleService
does), or wire each needed mapping manually with the necessary mapping and namespace.
d
Ok. sounds like coldbox's module service has some code I can reuse. for now it seems easier to do the first option - use it without the namespace. and HyperBuilder was injected into my cfc but now HyperBuilder can't find Hyper.models.HyperRequest at line modules\hyper\models\HyperBuilder.cfc:15
@elpete is hyper coded to only work within a Coldbox app?
Copy code
new Hyper.models.HyperRequest();
For this to work I would need a mapping for "Hyper".
e
You can create that mapping in your Application.cfc. (ColdBox does do that automatically as well.)
Hyper can work in any CFML application.
d
Sure. its the setup that has been a pain though. Well not really, its just that the documentation is missing for this exactly.
@elpete How is it suppose to work in any cfml app? I created the mapping for "Hyper" and now I'm getting this error:
Copy code
The DSLNamespace: box cannot be used as it requires a ColdBox Context <br>The error occurred on line wirebox\system\ioc\Builder.cfc:519
e
Sure. You’re on the possible but not documented path. Actually, you are on the strangest of the three supported paths — WireBox but not ColdBox. I’ll be honest, I don’t ever consider that flow (though it is still possible). You will need to provide values in your WireBox config for the properties that are trying to be injected.
Also, feel free to send a PR for the docs showing using this outside of ColdBox / with standalone WireBox. 👍🏻
d
I can do that. I like contributing to docs when I can. I have enough learning experience with this path now.
looks like I need to provide a guide in wirebox docs and in hyper docs.
e
So, my thought would be something like this:
Copy code
map( "HyperBuilder@hyper" )
    .to( "hyper.models.HyperBuilder" )
    .property( name = "interceptorService", value = javacast( "null", "" ) );
d
Not sure if you wanted me to try that but I did and got
Copy code
Element REF is undefined in a CFML structure referenced as part of an expression.
The error occurred on line wirebox\system\ioc\Injector.cfc:1111
I still have my mapping for Hyper and my wirebox config looks like this:
Copy code
component {
    function configure(required binder){
        // The WireBox configuration structure DSL
		wireBox = {


            // DI for custom models
            scanLocations = [
                "models"
            ],
			// Scope registration, automatically register a wirebox injector instance on any CF scope
			// By default it registeres itself on application scope
			scopeRegistration = {
				enabled = true,
				scope   = "application", // server, cluster, session, application
				key		= "wireBox"
			},

			// DSL Namespace registrations
			customDSL = {
				// namespace = "mapping name"
			},
			
			// Custom Storage Scopes
			customScopes = {
				// annotationName = "mapping name"
			},
			
			// Stop Recursions
			stopRecursions = [],
			
			// 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="", name="", properties={} }
			]			
		};

        // DI for forgebox modules (not entirely working)
        // binder.mapDirectory('modules');

		binder.map( "HyperBuilder@hyper" )
    		.to( "hyper.models.HyperBuilder" )
    		.property( name = "interceptorService", value = javacast( "null", "" ) );

        binder.map("DuoClient").to("login-security.DuoClient");
    }
}
first path: Coldbox second path: Legacy app without Coldbox and Wirebox
b
I would recommend just adding in ColdBox, lol
d
third path: Wirebox without Coldbox.
b
Even if you don't route requests though it, you can still bootstrap it into the application scope in your
Application.cfc
and let it do its thing loading modules and such
Then you can get the models from WireBox like before
Copy code
application.wirebox.getInstance( 'hyperBuilder@hyper' )
e
That error might mean WireBox has a null bug.
The other options is a struct with a processState function that is a noop
d
so without Coldbox and wirebox I would ahve to do:
Copy code
this.mappings['Hyper'] = 'modules/hyper';

var hyper = new Hyper.models.HyperBuilder();
and I think that is it? This is much simpler.
Yup that worked. So forget about using forgebox modules with Wirebox in a non-Coldbox application - that is too complicated.
too complicated and I'd go as far as saying not even supported or I'd say its broken or I'd say the worst developer experience.
b
Keep in mind that only works for modules specifically designed to be usable outside of ColdBox. Many modules on ForgeBox have hard dependencies on the ColdBox framework.
👍🏾 1
d
True. I think most of those are prefixed with "cb"
b
too complicated and I'd go as far as saying not even supported
Not sure what you mean there. ColdBox can always be bootstrapped into another application and used to load modules and there's nothing wrong with that. I've done that for several clients who had a legacy site they wanted to drop some box goodness into.
d
which was intuitive enough to understand for me.
b
I think most of those are prefixed with "cb"
No, the prefix means nothing, lol. That's just a convention Luis used to use back in the day for all his modules. It's basically random.
I mean
cbFoo
may be more likely to depend on ColdBox, but it's not really a good indicator.
Any modules is inherently intended for ColdBox, the question is really just whether it has code inside of it that uses ColdBox specific bits or not.
d
Isnt there a push or "movement" to use forgebox for all cfml packages?
b
Sure, but that's irrelevant
Being on ForgeBox doesn't make something a module, it just makes it a package.
Technically, just a folder having a
box.json
makes it a package
being on forgebox makes it a published package 😆
Having a
ModuleConfig.cfc
makes something a "module" (be it ColdBox, CommandBox, or Contentbox)
The thing is, there are some modules which were written very generically so you could manually instantiate their CFCs without any hard dependencies on box-related stuff to help encourage non-boxers to be able to use them outside of ColdBox
d
Yeah and my generic module depends on Hyper which took all day today to figure how to wire it up.