autowire errors if model filename different than returntype

Maybe I missed something but I was unable to autowire a model file
unless the model file had the same name as the returntype of the init
method. I am using CB3 M4

What I tried to do was create a mapping


then in the model file I had


<cfcomponent name="notifyService" displayname="notifyService"

    <--- Dependencies --->
  <cfproperty name="notifyDSN" type="coldbox:datasource:notifyDSN"
scope="instance" />

    instance = structnew();

    <cffunction name="init" output="false" returntype="notifyService">
       <cfreturn this>

The handler


<cfcomponent extends="coldbox.system.EventHandler" output="false"
displayname="ehNotify" autowire="true">

    <--- Dependencies --->
  <cfproperty name="notifyService" type="model" scope="instance" />

So When I reinited the framework I would get the following error:

"Error Type: Autowire.AutowireException : [N/A]
Error Messages: Error autowiring handlers.ehNotify. The value returned
from the init function is not of type notify. If the component name is
specified as a return type, its possible that a definition file for
the component cannot be found or is not accessible."

So not sure why this is happening for the moment I renamed the file to
match instance.


If returntype is not important to you, try changing the returntype in the code below to “any” and see what happens.

  • Gabriel

hmm, that did work. Yeah returntype is not really important to me, at
this point. I was just following what I have done in the past and the
documents. Guess I always had the names match so never noticed.

I guess I figured the modelMappings file would pass the name so
returntype would work.