wirebox component annotations

I was trying to reduce the most basic wireboxing on a site, but I can’t get this to work. Luis I emailed you this once before, I guess you haven’t had a chance to look at it yet.

According to the documentation I should be able to do this on the component.

component alias = “myService@something” {}

Which results in it not being setup with an alias at all, according to the documentation it says it is good for mapDirectory(). Now I might be wrong here, but my assumption would be that if WireBox can Di into this component, then WireBox should be able to automatically alias it this way.

Anyway, as that doesn’t work I then thought if I added this to the module config, it would work. But no this doesn’t work either.

binder.mapDirectory("#moduleMapping#.model");

So the question is now, is this not achievable, bugged or I am not understanding the documentation and the intended usage?

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/
Google+: http://plus.google.com/113032480415921517411

Andrew, I just tried and it works for me. I created an empty ColdBox app with a file called foobar.cfc in the model directory that looks like so:

component alias=“myService@something” {}

I then put the following in my config/WireBox.cfc

mapDirectory(“model”);

And the following in my test view:

<cfdump var="#getmodel(“myService@something”)#">

It dumps out an instance of model.foobar.

Perhaps the difference is that you’re working with a module. Can you expound on your setup?

Also, for what it’s worth, the relevant code that processes the alias annotation is in the “process” method of mapping.cfc

// Alias annotations if found, then append them as aliases.
if( structKeyExists(md, “alias”) ){
thisAliases = listToArray(md.alias);
instance.alias.addAll( thisAliases );
// register alias references on binder
for(x=1; x lte arrayLen(thisAliases); x++){
mappings[ thisAliases[x] ] = this;
}
}

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

hmmm, weird if you ask me as I even looked at the code that generates the alias and the dumped the mappings out on the screen and all I see is a cut down version of the component name. Which the code backs up as that is all it does.

But is there also any need to do a mapDirectory(), I mean running a cfdirectory over these files is not something that is fast, especially since wirebox has already done it once to wire them.

But is there also any need to do a mapDirectory(), I mean running a cfdirectory over these files is not something that is fast, especially since wirebox has already done it once to wire them.

No Brad what I mean is this.

I have a service in the model directory with DI properties, yet to put the alias annonotation on this I have to do mapDirectory() on that directory again. My argument is that WireBox has already been traversing to inject what it has to inject, yet it can’t check for the alias on the component at the same time… Why!!

That is incorrect. WireBox doesn’t do any directory traversal for injection. It processing injections for a single component at a time as the component’s mapping is created based on the metadata stored in the mapping. Mappings are only create after WireBox knows about a CFC and that happens in one of two ways:

  1. You create an explicit mapping (via mapDirectory() or map(), or mapPath())
  2. WireBox “finds” it based on scan locations and the name you specified

The reason aliases won’t work with scan locations is because WireBox can’t process metadata for a component it doesn’t know about yet. At the point WireBox is processing injections for an object that had no explicit mapping, it is too late for aliases to be of any use because you have already told WireBox where it is and it has been created. WireBox cannot know information about a CFC before it knows the CFC exists.

You seem to think that WireBox does some sort of magic background loading of component information but it doesn’t.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Really Brad, you might want to start using ContentBox and ColdBox more then. Because any component inside the normal directories are indeed scanned. In fact it is because of this scanning that I continually see the timeout has occurred due to the cfloop taking too long to run, which is always the Wirebox traversing the directories ColdBox tells it too.

Now as I have a basic ContentBox installation here, then how do you explain without me telling Wirebox or ColdBox to map that directory, that it is actually doing the DI?

Are you sure you are with me on this Brad?

So in this case 1 goes out the window as ColdBox already does this internally for ContentBox and number 2 is more to what ColdBox and ContentBox actually deliver for us.

So pleas explain how ColdBox and ContentBox know how to traverse the models directory and inject what it has too, but can’t setup the alias at the same time?

I am not going to spend another argument with you here, this is something that I brought to Luis’s attention 12 months ago and he said he would look into this, well he hasn’t and it is still a problem. Not only because I can’t use the alias to name the component, but I also habe to add mapDirectory again to do this.

You need a hug, Andrew?

Now try that as a module instead.

lol…

Jason it has been frustrating me for 12 months, every time I revisit this I get the same problem. Now the interesting thing is, is that mapDirectory() has from what I can tell no connection with Alias at all, at least that is what I am seeing.

I think I am beyond a hug on this one though…

@Brad, sorry I went back to the original post and I should have added the following conditions as it might make a difference.

This is a ColdBox module inside of ContentBox and what I am trying to stop me from doing is adding this line to ModuelConfig.cfc and also why alias is not being picked up like the following.

binder.mapDirectory("#moduleMapping#.model");

your tests did not conclude if it works from a module or not, you only tested it from a standard model directory. Also your tests included adding the map directory, with which I think should not be needed as per my explanation that wirebox has already traversed this folder to do its dependency injection, at which point I am asking is there any reason that the alias could not be picked up at that point and not by having to do another mapDirectory().

I am sorry Brad because I don’t see why it can’t…