Transfer Setter Injection using Lightwire

Hi group,

I managed a while back, using the ColdBox docs, to get Ligthwire
injecting an instance of ColdBox into my Transfer objects. That seems
to be working great but I'm now wanting to take things to the next
level and wonder if anyone could point me in the right direction?

I've got a Transfer object called "SCE" and I need to inject on load
of that object another one called SCEType. The SCEType is declared in
the Lightwire config like so -

<bean id="SCEType" class="model.enrolment.sceType" lazy-init="false"
singleton="false" />

I thought it was the case with the Transfer Observer that when I call
a Transfer object the system would match up any setters I have in my
beans. So for example if I put in a setSCEType Lightwire would know to
inject my SCEType bean into that method...

I tried with this method but I don't seem to get anything back when I
call my getter....

  <cffunction name="setSCEType" access="public" output=false
returnType="sce" hint="Sets an instance of an SCEType object">
    <cfargument name="SCEType" type="any" required=true hint="The
instance of an SCEType object to be used" />
    <cfset variables.instance.SCEType = arguments.SCEType />
    <cfreturn this />
  </cffunction>

I'm obviously missing something :slight_smile: Could anyone help by giving me
some pointers please?

Thanks again,
James

You can inject(autowire) ColdBox in your decorator by adding a
cfproperty to your transfer object decorator

  <cfproperty name="Coldbox" type="coldbox" scope="instance" />

    <cffunction name="getColdbox" access="public" returntype="any"
output="false">
      <cfreturn instance.coldbox />
    </cffunction>

After that you can do stuff, within your decorator, like
getColdBox.getPlugin("ioc").getBean("myService").getMyServiceMethod()

Ernst