[coldbox-4.0][cborm-1.0.1] service injection problem

Can someone help me out? I’m trying to inject a service, personService, that extends cborm.models.VirtualEntityService into a model. I’m getting the error “The DSL Definition {JAVACAST={null},NAME={personService},ARGNAME={},DSL={models:Services:PersonService},VALUE={null},SCOPE={variables},REQUIRED={true},REF={null},TYPE={any}} did not produce any resulting dependencies”

In my interceptor, I inject a model (model:BaseIntranet) and that works fine. I can access all the methods in that model, in that model’s definition I’m using the line property name=“personService” inject=“models:Services:PersonService”; to create the person service. There are two other properties, one injecting a datasource, the other a logger that work fine.

The person service exists at /models/Services/PersonService (my coldbox app is at the web root)

It is:

component extends=“cborm.models.VirtualEntityService” singleton{

// Constructor

public PersonService function init(){

return this;

}

}

So you can see, it’s not really doing anything. I removed anything till I get this to inject correctly. I can inject “entityService:Person” (There is a Person defined under /models/Entities/Person.cfc) and it works just fine. I tried that just to see if dependency injection was working correctly. cborm is installed and working, it created my Person table when I started the framework.

This particular setup was working on cb 3.8.0. I’m just starting to move this app to 4.0.

Just for giggles, I tried injecting model:Services.PersonService, models:Services:PersonService, model:PersonService, models:PersonService. I created a mapping (personService = “models.Services.PersonService”) in the wirebox config as well and tried just plain property name=“personService” inject;

I know this is going to be something stupid, I just can’t seem to find it.

Thanks in advance for any assistance.

Scott

If you haven’t created a specific mapping, the following DSLs should all work:

  • services.personservice – namespace defaults to “id:”
  • model:services.personservice – “model:” is just an alias for “id:”
  • id:services.personservice – This is technically the canonical form
  • models.services.personservice – Wirebox would just find this by full component path

The following DSLs are all invalid (without an explicit mapping):

  • models:Services:PersonService – “models:” is not a valid namespace
  • model:PersonService – personservice is not the full mapping name-- you forgot the “services” package
  • models:PersonService – “models:” is not a valid namespace
  • PersonService – personservice is not the full mapping name-- you forgot the “services” package
    Now, If you created a mapping that changes what DSLs would work, but you didn’t show the code you used to create your mapping so I can’t confirm if you did it right. The following mappings would work:
  • map( ‘personservice’ ).to( ‘models.services.personservice’ );
  • mapPath( ‘models.services.personservice’ );
  • mapDirectory( ‘models’ );
    Well, technically there’s a infinite number of possible mappings given all the options and other names you could call it, but these are the most likely.

So, IF you used one of those mappings, the following DSLs would ALSO work in addition to the working list above:

Now, as to why it’s not working for you I don’t know. You’ve tried too many things all at once to really know what the issue is. Back up and use one of the first working DSLs I showed, then report back to us what the error is and we’ll work from there.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Brad,

Thanks for getting back so quickly. I appreciate it. I tried:

property name=“personService” inject=“model:services.personservice”;

and got (pretty much the same):

The DSL Definition {JAVACAST={null},NAME={personService},ARGNAME={},DSL={model:services.personservice},VALUE={null},SCOPE={variables},REQUIRED={true},REF={null},TYPE={any}} did not produce any resulting dependency

I actually did try them all, one at a time, with framework reinits in between but changed nothing else. They all got the same. The one above however, was the first.

Brad’s instructions should work for you, as I just tested recursion down to four deep on a new CB install. Can you instantiate that CFC directly with createObject()? If there’s a syntax error, Wirebox won’t register it and will also give you that error (which has had me pulling out my own hair before).

If that works, for a quick fix you can add the following to your Wirebox config:

scanLocations = [‘models/Service’],

Then just call:

property name=“PersonService” inject=“PersonService”;

Jon,

I did have that exact same problem earlier. There was a syntax error that caused me grief. I found it and fixed it. Creating it directly was a good call, wish I’d have thought of that. (I found the syntax error earlier by accident)

Unfortunately, though that doesn’t seem to be it either. Using CreateObject, I could successfully instantiate it with no error. Looks exactly like it should.

On a side note, if I use that scan location, I should be able to call property name=“PersonService” inject; right?

It doesn’t work for me without the DSL name, but maybe there’s some ninja stuff that Brad and Luis know that I don’t. :slight_smile:

Since that’s an ORM object, is your ORM event handler in place and correct? Brad schooled me on that a few days ago after I accidentally removed it from from my App.cfc while upgrading an app to CB4 and filed a bug report.

ormSettings={
eventHandler = "cborm.models.EventHandler",
... etc …
}

Note
property name=“foobar” inject;
works on Adobe ColdFusion but not on Railo, err… Lucee.

I guess I need to go enter that ticket again on the Lucee bug tracker. :slight_smile:

It throws a syntax error though, so you’d know it if you’re on Railo.

Can the OP put up a code sample we can try? There must be something else going on in your environment.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Sorry it took so long. I grabbed the whole CB app. The only difference is I moved the modules in to the modules dir. They are external to the application on my server. Just to make sure that wasn’t going to screw it up, I took the zip file and dropped it onto another CF server and got the same results. The app in question is at https://www.dropbox.com/s/l4s3o5aoplgoc1g/huck.zip?dl=0

I know that’s the whole thing and it’s fairly large but I haven’t had a chance to slim it down.

Thanks for taking a look at this for me…it’s been driving me nuts…

Scott

Hi, I got your app running on a CommandBox embedded server after a few tweaks to the code. On a site note, CommandBox is freaking great for this kind of ad-hoc stuff. I pulled up the interactive shell and literally typed these two commands:

cd D:\Downloads\huck\huck
start

Boom, two seconds later I had a running CF server pop itself open in my browser using that folder as the web root. Oh, I guess I did need to install ColdBox:

install coldbox

Done! :slight_smile:

Your bootstrap files are missing so it’s a little rearranged, but a dump appears on the screen that includes a logger, data source, and an instance of models.services.personservice. So, I’m not entirely sure what I’m supposed to be looking at since that all appears to be working.

I do have some notes on a few things you’re doing:

  • Don’t inject the session storage model as “local.storage”. Adobe might let you get away with that, but Railo errors and rightfully so. “local” is an actual CFML scope so your actual variable is “variables.local.session” which means when you try to use “local.session” it’s not defined. That is also a horribly confusing variable name. Also, don’t name variables 'session" either since that is also the name of a built in scope. I changed the property name to “sessionStorage” in the variables scope. Remember, all injected dependencies are global to the entire component whether you put it in variables, instance, or this. You can’t inject into a local scope.
  • Your custom message box model extends external.modules.vendor.cbmessagebox.models.MessageBox. Don’t do this. Instead, extend cbmessagebox.models.MessageBox since the messagebox module creates a mapping called /cbmessagebox. This keeps your app more flexible and doesn’t tie it to the physical location of the module.
  • Enable the cfbmessagebox module
  • Set this.dependencies = [“cbmessagebox”] inside huckmessagebox so they load in the right order
  • Your syntax for default argument values is wrong. It’s not default=true, it’s just argName=true. You had it wrong about 8 times in messagebox.cfc which was causing errors with dismissiable being a null value.
  • You seem to be confused about how to map a model in the config/WireBox.cfc. Don’t add anything to the customDSL struct-- it doesn’t do what you think it does. In fact, that may have been the source of your problems.
  • What is the purpose of your huck model? I’m not sure you need it at all.
  • If you need person service, just inject it directly where it’s needed
  • If you need a data source, just inject it directly where it’s needed
  • If you need a logger, just inject it directly… you get the picture. There’s already a factory that gives you things and it’s called WireBox :slight_smile:
  • Your logger injection DSL is wrong. “logbox:logger” isn’t even valid, but apparently it doesn’t error out. Check the docs for valid LogBox DSL namespaces. http://wiki.coldbox.org/wiki/WireBox.cfm#LogBox_Namespace You’re getting a logger named “logger” which isn’t what you want
  • I would recommend using “logbox:logger:{this}” as it gives you a logger actually named after the CFC it’s being injected into which is why you always inject a logger in wherever you need it and don’t just pass one around.
  • Why is huck being put in session every request? Firstly, you shouldn’t ever need to write code to persist a model-- that’s what WireBox is here for. If you want huck to live in session, just add ‘scope=“session”’ at the top of the huck CFC and then simply ask WireBox for it any time you need it. The session storage will be done for you. The entire interceptor serves no purpose, nor the boilerplate of getting it out of the session storage model either. It’s all just extra work wireBox could be doing for you.

And finally…

stop

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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