as someone new to CB, I have been pouring over the existing CB docs
and then comparing them to the "what's new in 3.0" section trying to
wrap my mind around some of the new and existing concepts and best
practices.
i am having trouble fully understanding what appears to be only subtle
differences in some of the terms that are being used throughout.
I am not quite sure i have full grasp on what is what..
can someone give a quick overview of the following and how they differ
from one another (where and when to use):
- Autowire interceptor
- Model Integration
- Wirebox (this guide still has a coming soon on it)
I think i am beginning to see what each are and how they differ but
would like to hear from someone else.
Hi there. Let me first say that it’s great that you have taken the time to read through the docs first, as this gives a great foundation to build your Coldbox knowledge on!
The autowire interceptor is used to allow for performing dependency injection within your handlers, interceptors, and plugins. In the past, it also enabled dependency injection within your model objects as well, but as of 3.0M5, models will be “wired up” for you with or without the autowire interceptor enabled. If the autowire interceptor is not enabled, your handlers, plugins, and other interceptors won’t be examined by the framework for injections. As a best practice, it is good to just always enable the autowire interceptor.
Model Integration refers to the fact that you can, simply by adding annotations like “<cfproperty”, automatically put one object into another. And believe me, it would be a rare case when your model objects WON’T need to “talk to” another model object. Without Model Integration, you can still accomplish the same thing by hand, but it takes a lot more code and creates some code maintenance hassles that you would want to avoid. The old fashioned way of doing it is by using “createObject” calls inside of your components.
WireBox is the official name for the whole dependency injection framework. If you’ve heard of Coldspring or Lightwire, WireBox is the equivalent of those two things (only much better ). As of right now, WireBox is baked in to Coldbox and is not a standalone framework; but very soon, Coldbox will give birth to WireBox and it will be available for use outside of Coldbox as a standalone framework.
thank you for such a superb response. it did indeed help… and i believe my understanding was very close to your explanation.
i do have a couple of fine points i like to solidify if i may:
autowire seems to be clear to me, noting that it pertains to plugins, handlers and Interceptors and is for DI after creation.
so the fact, that i am injecting my own model using say cfproperty name=“mymodel” inject=“model” into one of my handlers does not mean i am necessarily using “model integration” but rather just using the autowire interceptor to autowire my model into the handler using DSL.
does that sound like an accurate statement?
your description below of “Model Integration” seems to imply that it refers to model objects and not other objects (plugins, handlers, etc…), is that accurate? Is Model Integration more about doing for model objects what has always been done for handlers, plugins, etc…?
perhaps my making a distinction between the 2 concepts is incorrect, but it appears that what i read under the Model integration section implied that i cannot use certain functions, namely getmodel()… There seems to be differences and limitations depending on the MVC portion of the particular object, is that true?
since the concept of Model Integration is more abstract than lietreal i am unclear on when i need to turn this setting on in config.cfc and to which objects it applies. by uncommenting this do i get my models examined for injections?
// Model Integration
models = {
…
}
in a test project, i uncommented out the code in nr 4 above (leaving all the properties to their defaults) while having one model cfc in the models folder. That particular model also has a method that i have chosen as the recipient of A Custom Security Validation Object. The method is of course called ( as per the docs): userValidator. It is properly registered as the validator in the config.cfc etc… ( i am reading/learning about the Security Interceptor at the same time i am learning about these other concepts we are discussing.)
in any event, can you imagine any reason if using it as the validator would preclude it from getting its dependences resolved OR have I missed something somehere on Model Integration/Wirebox?
i have added the following to the top of my cfc as merely a test
But… In none of the defined methods for the security object (not even userValidator) can i refer to instance.SessionStorage without throwing an undefined error–no matter what i do… I suspect that this model is not being examined for dependencies??
your explanation of wirebox was exactly by guess (yes, i am familiar with ColdSpring ), thanks