views:

91

answers:

2

I'm rereading ColdSpring in 5 minutes. It says "The UserService needs the UserGateway, and the UserGateway needs the ConfigBean". No it does not! The UserService does not need anything. It doesn't call UserGateway.

All it does is set a variable that it happens to call userGateway by coincidence, but it doesn't call the User Gateway component.

Help me understand this apparently simple scenario!

+3  A: 

You have to remember that this starter application intentionally doesn't explain everything so as to prevent confusion. When completely configured, the sample application will initialize all three components. The UserService CFC has the responsiblity of setting and getting the User Gateway Component, the User Gateway component has the responsiblity of setting and getting the Config Bean component, and the Config Bean component is designed to set and get application settings (in this case, just datasource information).

I wouldn't fret too much over this for now if you don't understand how it all works; ColdSpring's reference guide will bring it all into focus for you.

KeRiCr
A: 

The line "The UserService needs the UserGateway" means that one of the functions contains a variable or call that needs the UserGateway, not necessarily that the UserService has any intrinsic need for it. This is at the core of what ColdSpring does... manage dependencies. If the UserService was not configured to be injected with the UserGateway, then when a variable that "just happens" to call or need the UserGateway is created, it would not be able to find the needed UserGateway unless you manually instantiated it.

Look under "More Advanced" in the ColdSpring Quickstart Guide at "Factory Beans", for example.

The 5 minute example was just that, an example, you didn't see any calls in those functions that needed the UserGateway, but when you do have a need for it, you'll be glad it was injected for you so that you don't have to do it yourself.