[coldbox 3.8.1] Acessing models and services in external location

I have an application (App1) setup with a heap of models and services in it’s “models” folder.

I am setting up another application (App2) which needs to access the models and services in the App2/models folder, using wirebox to inject dependencies (services) into models.

It is generally working fine, but seems very flaky so I am sure I have something wrong with the setup. Currently I am receiving an error that a dependency can’t be injected into an object.

Here is my setup

Application.cfc

`

cfcLocation=[“model”,"/Users/jason/SitesRailo/webapps/membes/model" ],

`

config/Coldbox.cfc

`

conventions = {
modelsLocation = “model,/Users/jason/SitesRailo/webapps/membes/model;”
};

wirebox.scanLocations = [“model”,"/Users/jason/SitesRailo/webapps/membes/model"];

`

Does this seem right, or am I missing something?

Many thanks in advance for any help!

Jason

> cfcLocation=[“model”,"/Users/jason/SitesRailo/webapps/membes/model"],

This really has nothing to do with ColdBox, it’s just an ORM thing to locate ORM entities.

> conventions ={
> modelsLocation =“model,/Users/jason/SitesRailo/webapps/membes/model;”
> };

Hey, that’s cool. I didn’t realize you could pass in a comma-delimited list of model conventions. I just reviewed the code and tried it and it works.

> wirebox.scanLocations =[“model”,"/Users/jason/SitesRailo/webapps/membes/model"];

So, this is actually redundant. ColdBox automatically sets your model convention(s) into WireBox as scan locations so adding them again doesn’t accomplish anything.

I would recommend moving your shared models somewhere outside both sites in a shared location and just point to that location with an app-mapping in each app. If you really want, you can leave them in App1, but at least create a mapping in app two so you don’t have that annoying long and brittle file path all over App 2.

I don’t see anything wrong in the setup you have (other than the redundant setting of scan locations). If you are worried that your scan locations are set up right, just stick this in a view and dump out what’s currently in WireBox:

Other than that, you’re going to have to give us way information about what seems “flaky” and actually tell us what the “error” is that you’re receiving.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks Brad! Dumping out the scan locations showed me the problem. The second mapping I have set for modelsLocation is an absolute path (/Users/jason/SitesRailo/webapps/membes/model), but coldbox is converting it to relative, so this is creating a scan location of (/Users/jason/SitesRailo/webapps/membesadmin/Users/jason/SitesRailo/webapps/membes/model;)

So the question now I guess is how to specify an absolute path for ‘modelsLocation’… or is that even possible…

Thanks again!!

You don’t. Conventions are, by nature, relative to the web root. If you want to add extra scan locations that point to arbitrary places on your hard drive, add them directly in the WireBox config.

So I would leave ONLY “model” as your model convention, and add the full path as the only (additional) scan location in your WireBox config.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

I found the problem with the absolute path… it was the semicolon at the end… once I removed that the path was spot on.

Now getting the following error:

invalid component definition, can’t find .Users.Jason.SitesRailo.webapps.membes.model.SettingService

SettingService is a component in App1/model that is being injected by a component also in App1/model with property name=“SettingService” inject=“model:SettingService” persistent=“false”;

I think you may need to create a mapping like I suggested earlier. Thinking about it now, ColdFusion in general doesn’t allow you to create CFCs just anywhere on your hardrive. You have to have a dot-delimited component path to reference that has to be relative to your web root or a mapping you’ve created.

Application.cfc
this.mappings[ ‘sharedModels’ ] = ‘/Users/jason/SitesRailo/webapps/membes/model’;

wirebox.scanLocations =[ “sharedModels” ];

propertyname="SettingService"inject=“sharedModels.SettingService” persistent=“false”;

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

That was it!! Once I set it all up with the the mappings like you suggested it worked! Note that i had to set the mapping up in both App1.Application.cfc and App2.Application.cfc.

Thanks a TONNE Brad… I’ve been pulling my hair out over this since yesterday… couldn’t have crunched it without your help. Thank you!!!

Jason