OK,  So let's try something together...

Open up your ColdSpring.xml file and find the definition for: <bean
id="CMSGateway" class="Application.model.Gateways.CMSGateway" />

Change it to this:

<bean id="CMSGateway" class="Application.model.Gateways.CMSGateway">
  <constructor-arg name="ApplicationConfiguration"><ref bean="
ApplicationConfiguration" /></constructor-arg>
</bean>

( Note: Application Configuration must also have a bean definition in
ColdSpring for this to work. )

Now, ColdSpring knows to make the ApplicationConfiguration object available
to your init method. For the sake of a metaphor, ColdSpring is now pitching
the ApplicationConfiguration object to your init method, thus, we must
catch it...

Open your CMSGateway object.

Make this modification:

<cffunction name="init">
  <cfargument name="ApplicationConfig" type="any">
        <cfset Variables.ApplicationConfig=arguments.ApplicationConfig >
        <cfset Variables.searchCriteria={}>
        <cfset Variables.searchCriteria.domainname=
Variables.ApplicationConfig.getConfigSetting("domainname")>
        <cfset Variables.searchCriteria.id<http://variables.searchcriteria.id/>
="">
        <cfset Variables.searchCriteria.language="">

        <cfreturn THIS>
    </cffunction>



See if that works?


DW



On Mon, Nov 21, 2011 at 10:42 AM, marc <[email protected]> wrote:

> Hi,
>
> I am not sure if this post belongs in the MG or the Coldspring forum, but
> here goes:
>
> I use Coldspring with my MG application and I have a component like this:
>
> <cfcomponent displayname="CMSGateway"
> extends="Application.model.Gateways.BaseGateway" output="false">
>
>     <cffunction name="init">
>         <cfreturn THIS>
>     </cffunction>
>
> [....]
>
> This component is defined in Coldspring.xml: <bean id="CMSGateway"
> class="Application.model.Gateways.CMSGateway" />
>
> I want to make a variable accessible to all functions in this component
> and so I put it in init():
>
>     <cffunction name="init">
>         <cfset Variables.searchCriteria={}>
>         <cfset Variables.searchCriteria.domainname="mydomainname">
>         <cfset Variables.searchCriteria.id="">
>         <cfset Variables.searchCriteria.language="">
>
>         <cfreturn THIS>
>     </cffunction>
>
> This works and all my functions have now access to the
> Variables.searchCriteria variable. It gets initialised once and I don't
> have to put this code in all functions that need it.
>
> Since "mydomainname" is defined in the Applicationconfiguration bean
> (ModelGlue.Bean.CommonBeans.SimpleConfig in Coldspring.xml), I change line
>         <cfset Variables.searchCriteria.domainname="mydomainname">
> to
>         <cfset
> Variables.searchCriteria.domainname=getApplicationConfiguration().getConfigSetting("domainname")>
>
> and add
>
>     <cfproperty name="ApplicationConfiguration">
>
> in the pseudo-constructor area just above the init function. Using
> Dependancy Injection I should be able to call getApplicationConfiguration()
> to get a reference to ApplicationConfiguration. So I have now
>
>     <cfproperty name="ApplicationConfiguration">
>
>     <cffunction name="init">
>         <cfset Variables.searchCriteria={}>
>         <cfset
> Variables.searchCriteria.domainname=getApplicationConfiguration().getConfigSetting("domainname")>
>         <cfset Variables.searchCriteria.id="">
>         <cfset Variables.searchCriteria.language="">
>
>         <cfreturn THIS>
>     </cffunction>
>
> But when requesting a page I get an error
>
> "Bean creation exceptio""n during init() of
> Application.model.Gateways.CMSGateway
> Variable GETAPPLICATIONCONFIGURATION is undefined.: "
>
> Obviously, I am not able to use Dependency Injection this way.
>
> I tried to move the block where I define Variables.searchCriteria _and_
> the associated cfproperty to the init handler of the parentclass
> (baseGateway.cfc) but that doesn't work either
>
> Is there something missing in my understanding of Dependency Injection or
> does it not work this way?
>
> Marc
>
> CF 9.01
> CS 1.2
> MG 'Gesture' 3.2 RC1
>
>  --
> Model-Glue Sites:
> Home Page: http://www.model-glue.com
> Documentation: http://docs.model-glue.com
> Bug Tracker: http://bugs.model-glue.com
> Blog: http://www.model-glue.com/blog
>
> You received this message because you are subscribed to the Google
> Groups "model-glue" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/model-glue?hl=en




-- 
Plutarch - "The mind is not a vessel to be filled but a fire to be kindled."

-- 
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog

You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en

Reply via email to