IOC and Autowire changes in 3.0 RC1

Hi,
  We have been using Coldbox in a new company application since CB 3.0
m6. We just downloaded and installed the new RC1 release that came
out and now our autowire isn't working. Was there a configuration
change for IOC or Autowire? We already made the change to use
inject="" on things and it was working normally in the m6 release
prior to this update.

  To be specific, it seems to be only happening on inject="Model" type
injections. We are using Lightwire for our IOC and have the Autowire
interceptor setup. I can post config files if necessary, but a point
out to the specific change would probably be enough.

Thanks!

There are no changes on model integration. However, you can not use property annotations with lightwire, so how where you doing this before?

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

That... is an excellent question. I don't know. I thought it was
supposed to work like that, and it seems to have been working like
that. Let me post our config files, maybe that will help. Forgive me
if I am attaching these wrong:
I will include Coldbox.cfc and Lightwire.cfc:

Coldbox.cfc:
<cfcomponent output="false" hint="My App Configuration">
<cfscript>
  // Configure ColdBox Application
  function configure(){

    // coldbox directives
    coldbox = {
      //Application Setup
      appName = "MyCompanyApp",
      appMapping = "",
      eventName = "event",

      //Development Settings
      debugMode = true,
      debugPassword = "",
      reinitPassword = "",
      handlersIndexAutoReload = true,
      configAutoReload = false,

      //Implicit Events
      defaultEvent = "Main",
      requestStartHandler = "Main.onRequestStart",
      requestEndHandler = "",
      applicationStartHandler = "Main.onAppInit",
      applicationEndHandler = "",
      sessionStartHandler = "Main.onSessionStart",
      sessionEndHandler = "",
      missingTemplateHandler = "",

      //Extension Points
      UDFLibraryFile = "includes/helpers/ApplicationHelper.cfm",
      coldboxExtensionsLocation = "",
      modulesLocation = "",
      pluginsExternalLocation = "",
      viewsExternalLocation = "",
      layoutsExternalLocation = "",
      handlersExternalLocation = "",
      requestContextDecorator = "",

      //Error/Exception Handling
      exceptionHandler = "Main.onException",
      onInvalidEvent = "Main.onInvalidEvent",
      customErrorTemplate = "",

      //Application Aspects
      handlerCaching = false,
      eventCaching = false,
      proxyReturnCollection = false,
      flashURLPersistScope = "session"
    };

    // custom settings
    settings = {
      ssl = true,
      "debug" = false,
                        "cfc.model.root" = "model.",
                        "cfc.com.root" = "com."
    };

    // Module Directives
    modules = {
      //Turn to false in production
      autoReload = true,
      // An array of modules names to load, empty means all of them
      include = [],
      // An array of modules names to NOT load, empty means none
      exclude = []
    };

    //LogBox DSL
    logBox = {
      // Define Appenders
      appenders = {
        coldboxTracer =
{ class="coldbox.system.logging.appenders.ColdboxTracerAppender" },
        fileLog = {
  
class="coldbox.system.logging.appenders.AsyncRollingFileAppender",
           properties={
            filePath = "logs",
            fileName = coldbox.appName,
            autoExpand = true,
            fileMaxSize = 2000,
            fileMaxArchives = 5
          }
        }
      },
      // Root Logger
      root = { levelmax="DEBUG", appenders="*" },
      // Implicit Level Categories
      info = [ "coldbox.system" ]
    };

    //Layout Settings
    layoutSettings = {
      defaultLayout = "Main.cfm"
    };

    //Register Layouts
    layouts = {
      login = {
        file = "Login.cfm",
        folders = "user"
      }
    };

    //cacheEngine
    cacheBox = {
      // The defaultCache has an implicit name "default" which is a
reserved cache name
      // It also has a default provider of cachebox which cannot be
changed.
      // All timeouts are in minutes
      defaultCache = {
        objectDefaultTimeout = 120, //two hours default
        objectDefaultLastAccessTimeout = 30, //30 minutes idle time
        useLastAccessTimeouts = true,
        reapFrequency = 2,
        freeMemoryPercentageThreshold = 0,
        evictionPolicy = "LRU",
        evictCount = 1,
        maxObjects = 300,
        objectStore = "ConcurrentStore", //guaranteed objects
        coldboxEnabled = true
      },

      // Register all the custom named caches you like here
      caches = {
        // Named cache for all coldbox event and view template caching
        template = {
          provider =
"coldbox.system.cache.providers.CacheBoxColdBoxProvider",
          properties = {
            objectDefaultTimeout = 120,
            objectDefaultLastAccessTimeout = 30,
            useLastAccessTimeouts = true,
            reapFrequency = 2,
            freeMemoryPercentageThreshold = 0,
            evictionPolicy = "LRU",
            evictCount = 2,
            maxObjects = 300,
            objectStore = "ConcurrentSoftReferenceStore" //memory sensitive
          }
        }
      }
    };

    //Interceptor Settings
    interceptorSettings = {
      throwOnInvalidStates = false,
      customInterceptors = ""
    };

    //Register interceptors as an array, we need order
    interceptors = [
      //SES
      {class="coldbox.system.interceptors.SES",
       properties={
           configFile = "config/routes.cfm"
        }
      },
      //SSL
      {class="interceptors.ssl",
      properties={

          checkSSL="true",
          pattern="",
          addToken="false"
        }
      },

      //Autowire
      {class="coldbox.system.interceptors.Autowire"},

      //Security - need to figure out ORM settings first
      {class="coldbox.system.interceptors.security",
      properties={
          rulesSource="xml",
          rulesFile="config/securityrules.xml.cfm",
          debugMode="false",
          validatorIOC="securityManager"
        }
      }
    ];

    //IOC Integration
    ioc = {
      framework = "lightwire",
      reload = true,
      objectCaching = false,
      definitionFile = "config.Lightwire"
    };

    //i18n & Localization
    i18n = {
      defaultResourceBundle = "includes/i18n/main",
      defaultLocale = "en_US",
      localeStorage = "session",
      unknownTranslation = "**NOT FOUND**"
    };

    //Conventions
    conventions = {
      handlersLocation = "handlers",
      pluginsLocation = "plugins",
      viewsLocation = "views",
      layoutsLocation = "layouts",
      modelsLocation = "model",
      modulesLocation = "modules",
      eventAction = "index"
    };

  }

</cfscript>
</cfcomponent>

Lightwire.cfc
<cfcomponent name="LightWire"
extends="coldbox.system.ioc.lightwire.BaseConfigObject" hint="A
LightWire configuration bean.">

  <cffunction name="init" output="false" returntype="any" hint="I
initialize the config bean.">
    <cfscript>
    var cfcComRoot = getController().getSetting('cfc.com.root');
    var cfcModelRoot = getController().getSetting('cfc.model.root');

    // Call the base init() method to set sensible defaults. Do NOT
remove this.
    super.init();
    setLazyLoad("false");

    addSingleton("#cfcComRoot#company.Utilities");

    addTransient("#cfcComRoot#company.ui.Menu");

    addSingleton("#cfcComRoot#company.Security","securityManager");
    addSingleton("#cfcComRoot#company.Theme","themeManager");
    addSingleton("#cfcModelRoot#.UserService","UserService");
      return this;
    </cfscript>
  </cffunction>

</cfcomponent>

I think you are mixing technologies and therefore the error arises.
If you are using lightwire then you will have to use the inject=“ioc” annotation as you are using an external object factory and not coldbox DI. If you are using inject=“model” then that means you are using ColdBox dependency injection and not lightwire.

I think there lies your error

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

I tried loading the model using the inject="ioc" and defining it in
the Lightwire.cfc config, but that still didn't work. It might be
that none of the dependency injection is working and it is just the
first thing failing is the model object.

One strange thing to note, if I use the "coldbox/system/plugins/
IOC.cfc" and "coldbox/system/ioc/adapters/LightWireAdapter.cfc" files
from M6 then it works fine. Everything loads up without a problem.

I would need examples I am not sure what you are doing.

Ahh I know what it is. You are using cfproperty tags right for wiring your model? Is this correct?

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Yes, it is correct. I'm sorry. I should have stated that at the
beginning, too. Does that make a difference?

Yes,

Pretty much you are mixin technologies. Property annotations on model objects is ColdBox dependency injection ONLY! Lightwire cannot do this, it can only do constructor or setter injection. In the pre RC1 releases the IOC plugin had a hack where I passed the object created by the ioc factory into ColdBox DI so it could be autowired for coldbox DI. However, this adds overhead and basically mixes DI strategies. This is now no longer supported.

Therefore, you can either forget about Lightwire and use ColdBox DI solely or migrate your injections to Lightwire syntax.

On another note, our LightWire that ships with ColdBox will be deprecated by 3.1 in favor of our own, WireBox. Second, LightWire in itself is no longer in development by Peter Bell.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Hey Luis, it's been under-developed recently, but it isn't unsupported. There are still plenty of people using it, and I'm looking at bringing a team together to more actively maintain it (if anyone is interested . . . )!

That said, I'm sure wirebox is a great option.

Just to ask, is it worth us discussing additions to LW to make it feature compatible with WB? Ping me offline if so . . .

Best Wishes,
Peter

Yea, that would be great Peter :), I have made considerable additions to LightWire and fixes that I would re-submit. Have you setup lightwire in github or anywhere I can send you the code? If not, it is in the /coldbox/system/ioc/Lightwire folder, I also created several test cases on the /testing folder in the repo.

I also, have created the new lightwire adapters that ColdBox and WireBox will use in order to support lightwire. So if you continue with it, then we can talk to it. You can check it here and give me your seal of approval :slight_smile: /coldbox/system/ioc/adapters/LightWireAdapter.cfc

I think also that his concern on his application right now is that he is mixing his DI factories. So I think that he needs to either fully use Lightwire or use WireBox DI. I think that if he already has everything setup in lightwire, why not just migrate the cfproperty annotations and move forward. Might be easier I guess, since he already has everything setup.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Cool - I’ll ping you next week. Final No Fluff conference of the season in Chicago this weekend and 4 decks to update. Once I’m done with that I’ll have some time to add a nice suite of tests and rewrite LW properly. Look out for a 2.0 around Xmas!

Best Wishes,
Peter

Awesome! Thank you for all of the clarifications. I will make sure
my Lightwire annotations are correct, and I plan to take close look at
the Wirebox stuff coming up.

Thanks again!