Help with injection of services within services

Hi all,

I would like to ask you why the following code does not work. In
summary, I have a virtual service where I want to inject two other
virtual services. I have read the wiki but I cannot figure out why
this is not working.
The error I get is:

A CFC with entityname model.services.ProfileService could not be
found.

********** 1ST SERVICE WITH REFERENCE TO 2 SERVICES
component extends="coldbox.system.orm.hibernate.VirtualEntityService"
accessors="true" singleton
{
  property name="profileService"
inject="entityService:model.services.ProfileService";
  property name="varPrivService"
inject="entityService:model.services.VariablePrivilegeService";

  BusinessViewVariableService function init()
  {
    super.init(entityName="BusinessViewVariable");
    return this;
  }

  function getVariableForGroup(groupId)
  {
                                    //
    var privileges = profileService.getPrivilegeNamesForProfile();
    var ids = varPrivService.getVariableIdsForPrivileges(privileges);
    ...etc...
  }
}

************** FIRST REFERRED SERVICE
component extends="coldbox.system.orm.hibernate.VirtualEntityService"
accessors="true" singleton
{

  ProfileService function init()
  {
    super.init(entityName="authorisation.Profile");
    return this;
  }

  function getPrivilegeNamesForProfile(profile)
  {
    var r = ormExecuteQuery("select p.privileges.name from Profile p
where p.id = ? ", [profile]);
    return r;
  }
}
************ SECOND REFERRED SERVICE
component extends="coldbox.system.orm.hibernate.VirtualEntityService"
accessors="true" singleton
{
  UserService function init()
  {
    super.init(entityName="autorisation.VariablePrivilege");
    return this;
  }

  function getVariableIdsForPrivileges(privilegeNames)
  {
    var r = ormExecuteQuery("select vp.varId from VariablePrivilege vp
where vp.accessPrivilegeName in (#privilegeNames#)");
    return r;
  }

}

Change it to

property name="profileService" inject="entityService:ProfileService";

Andrew,

I forgot to tell you the structure of my model directory: In model I
have my entities, and in a subdirectory services I have my services,
and in a subdirectory authorisation I have 4 entities related to
authorisation.

I have changed what you told me and it still does not work. Actually I
have tested with:

entityService:ProfileService
entityService:services.ProfileService
entityService:model.services.ProfileService

and I still get the same error.

I tried with the following and it seems to work (but I have no idea
why!!!)

property name="profileService"
inject="id:model.services.ProfileService";
property name="varPrivService"
inject="id:model.services.VariablePrivilegeService";

someone could give me a hint why this is working and why it doesn't
with "entityService" ?

thanks

My guess would be because entityService:entityName is the required solution.

Entity service:entity name is the dsl. So it requires the name of the entity. If you are using concrete objects then use id and the path or a binder I’d

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Social: twitter.com/ortussolutions | twitter.com/coldbox | twitter.com/lmajano

Hi,

I talked too fast. My solution is not working. Actually, it is working
at 50%. This is why I mean:

component accessors="true" singleton
{
  property name="userService" inject="id:UserService";

  /**
  * It sets the profile in the session.
  */

  function setProfileInSession(userId)
  {
    //wirebox =
createObject("component","coldbox.system.ioc.Injector").init();
    //var userService =
wirebox.getInstance("model.services.UserService");
    var profile = userService.getUserProfileByUserId(userId);
    session.profile = profile.getId();
  }

}

When I use the injection of wirebox and the getInstance() (commented
out in the code above), it works without problem.
When I use the property injection as in the example, it does not work
(Variable USERSERVICE is undefined). The mapping in the wirebox config
is:

map("UserService").to("model.services.UserService");

When I use:

property name="userService" inject="id:model.services.UserService";

I also get the same error (Variable USERSERVICE is undefined).

I've read the wiki and watched the video tutorials of wirebox and I
really do not have a clue why this is not working.

any ideas that could help?

Miro,

Seems something is amiss here. Have you tried reiniting the framework so the new metadata changes are picked up?

Also, I would suggest you turn on debugging via LogBox for the ioc package. This way, you have incredible amounts of information to help you debug issues like this. You can easily do this by going in your Configuration File and looking for the LogBox section. If not there, then look in the Advanced application template for the sample.

Once in the LogBox section, add a new implicit category for your package

logbox.debug = [ "coldbox.system.ioc" ];

This will add debugging information to whatever appenders you have defined for the "ioc" package. Whenever I hit a road block with anything in ColdBox, I always turn debugging on to get much more information

Good Luck

Luis Majano
CEO
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Social: twitter.com/ortussolutions | twitter.com/coldbox | twitter.com/lmajano