An object that represents a contact and self-validates using the cbvalidation
module.
Then spice up with some properties and constraints:
Here is our service layer and we have added some logging just for fun :). Notice that this object is a singleton and has some dependency injection.
Then spice it up
Now, some observations of the code:
We use the populator object that is included in WireBox to make our lives easier so we can populate objects from queries and deal with objects.
We also inject a reference to the object factory WireBox so it can create Contact
objects for us. Why? Well what if those objects had dependencies as well.
Let's put all the layers together and make the handler talk to the model. I create different saving approaches, to showcase different integration techniques:
Spice it up now
Now that you have finished, go execute the contacts and interact with it.
Now that we have seen all the theory and stuff, let's get down to business and do some examples. We will start with the full coding approach with no ORM and then spice it up with ORM, so you can see how awesome ORM can be. The examples will not show the entire application being built, but enough to get you started with the process of modeling everything. Here is a layout of what we will build:
I will create a DAO for this small example, so we can showcase how to talk to multiple objects. You can start a new application with CommandBox if you like:
Make sure you register a datasource in your ColdFusion administrator, we called ours contacts
and then register it in your ColdBox configuration so ColdBox can build datasource structs for us. This is totally optional, but we do it to showcase more injections:
config/ColdBox.cfc
Our Contact DAO will talk to the datasource object we declared and do a few queries. Notice that this object is a singleton and has some dependency injection.
Then spice it up