This document provides an overview of ColdSpring, an open source dependency injection framework for ColdFusion. It describes what ColdSpring does, including managing object dependencies and acting as a singleton object factory. It also defines key concepts like components, singletons, transients, and dependencies. The document outlines how ColdSpring can resolve dependencies through constructor injection and setter methods.
2. Ted Steinmann
Lead Developer
Hospital Dev Team
ImageTrend, Inc.
CF User 6 years
http://www.linkedin.com/in/tedsteinmann
3. Questions
Working on ColdSpring driven apps?
Built/implemented ColdSpring?
Not using ColdSpring?
Using something else?
Not Using components/cfcs?
4. What Does ColdSpring Do?
Object/Bean (Component) Factory
Singleton
Manage Dependencies
Much, much more…
5. ColdFusion Component
.cfc File containing data & functions
Building blocks to CF in an OO manner
Encapsulation
Inheritance
Introspection
6. What's a Singleton?
Design pattern
Single instance
Global access
One object
No State
7. What is a Transient Object?
Container
Short lived
Not Persisted
9. Dependency
One piece of a
program depends
on another to get
it’s job done.
a state in which
one object uses a
functionality of
another object
UserService
UserGateway
Config
10. Dependency
MVC/SOA
Dependencies between layers
Dependencies between objects
Controller Model View
11. What does that give us?
Prevents duplication of code/config
Separation of Concerns
Modularity
Encapsulation
19. Benefits of DI/IOC
Separation of concerns
Less coupling
Configuration without changing code
Components become easier to test
Birds eye view of the dependencies
Components are not tied to ColdSpring
20. Cost of DI/IOC
Configuration required
Longer startup times
Other?
21. References
ColdSpring
Quickstart
Reference Guide
What’s new in 1.2
ColdSpring Lite
Annotation-based
Dependency
Injection using
ColdSpring
Other
Dependency
Injection (Martin
Fowler)
ColdFusion
Components
Derby DB
Environment Config
Object Oriented
Programming
Notas do Editor
Intro Only
Questions:How many of you are working on applications which utilize ColdSpring?How many of you built those applications or understand how ColdSpring is setup?How many of you are not using ColdSpring?Using something else for DI/Object Factory not using compomentsFrom Description:(My opinion) - you should be using ColdSpring to manage your singletonsbrief overview of basic concepts and benefits of ColdSpringTalk about what a singleton, a transient object & dependency injection isWe'll walk through configuration of ColdSpring, inject some dependencies, cover some core features & review environmentConfig – former pilot (keep applications up and running)Hopefully those of you already using ColdSpring will stick around to the end of the preso or join us for drinks to share your experiences.
Interchangably (Java backgrounds may disagree) but in CF, ColdSpring is issuing ColdFusion components and it’s borrowed stuff from Java.
CFCs are building blocks that let you develop ColdFusion code in an object-oriented mannerEncapsulation: The technique of incorporating both code and data into one object such as a CFCCFCs can also enforce data types, check for required parameters, and optionally assign default values.Inheritance: One CFC can inherit the methods and properties of another CFC. Inheritance lets you build multiple specific components without rewriting the code for the basic building blocks of the components.Introspection: CFCs support introspection; that is, they can provide information about themselves. (such as getMetaData())
Concept create once and reuseComponentTypicallypersisted in the application scope.Update application startup, create necessary components that will be globally accessible
AKA, Domain objectMay be persisted in session or some other short lived scope
List: Showing us a list of usersBased on the ColdSpring QuickStart “ColdSpring in 5 minutes”Using an MCV approach to obtaining user recordsKnow want MVC stands for?Since we’re using an MVC approach: Service, Gateway, ConfigShow list page interfaceShow list page codeBear with me on the getting the user service from the bean factoryJust understand that the factory provides a instance of a user service cfcShow User Service Docs (getUsers Method)Show User Gateway Docs (getUsers Method)Show Config Bean Docs (getDSN)Show singleton interface and .cfmJust coldfusion components, and we’re getting them from the object factory.Show transient interface and .cfmSetters & gettersReturn to slides
http://en.wikipedia.org/wiki/Dependencyalso called Coupling (computer science), a state in which one object uses a functionality of another objectColdSpringquickstart refers to the MVC problem of Services depending on gateways which depend on configuration
What does coldspring do for us?Show dependents interface and .cfmNotice that I’m getting the gateway via the service, and config via the gatewayUserService has a method to getUsers, may not know how to actually query the database for those users, but it knows the userGateway doesLikewise, the UserGateway may not know what configuration is necessary to access database, but it knows the ConfigBean does know that.
What does this gain us?Prevents us from duplicating code (configuration)Separation of concernsMore gateways, config bean knowsModularityMakes it possible to remove/change individual components and how they function w/out distruptingChange database connection: Config, maybe gateways, Services don’t need to changeEncapsulationDifferent layers are protected from sharing too much information
Show ColdSpring.xml fileStore references to components & their dependenciesShow class path and filesSingletonsBorrows XML syntax from SpringShow Application PageNotice the application specific mappingsthis.root -> com & coldspringonApplicationStart: Create an instance of the ColdSpring factoryInitialize it and pass in coldspring file as a pathInvoking method “loadbeans” on the DefaultXmlBeanFactoryonRequestStart: init methodNeed a way to re-load singletons
From the ColdSpring Reference Guide:Think of a ColdSpring BeanFactory as the container, or holder, for your application's components. It will instantiate, configure, and resolve the dependencies among the components (beans) you place inside it. May have already said this:Don't get hung up on the "bean" syntax, coldspring relies on the "Java-bean" specification to resolve dependencies, but all the syntax says is register a component at this path under the name [myComponent] and return an instance of that object when asked for. Typically an instance is shared among all (Singleton)
When ColdSpring initializes it will inspect components and call any setters necessary injecting instantiated objectsConstructor argumentsSpecify dependencies in ColdSpring XML fileShow Config BeanCalls init function on components defined in XML fileSimple valuesShow UserGatewaygetUsersdatasourceSetter injectionUserService and Gateway don’t have dependencies defiendDon’t need to because of autowiringDuring Bean ColdSpring inspects component and says if I have a bean defined for this setter, instantate itShow UserServicesetUserGatewayColdSpring, “Do I have a UserGateway?”Pass instance of the userGateway to the userServiceRequires a little more codeWhy usePrevents Circular Dependency ComponentA Depends on ComponentB and ComponentB depends on ComponentA
What else can we do with ColdSpring?Import XML directive - New in ColdSpring 1.2Show ColdSpring FileDynamic PropertiesShow in codeSpecial syntaxEnvironment ConfigShow invokeShow XMLVarious environments determined by regex pattern matchingKey value configuration properties (returns coldfusionstruct)
Parent Beans – remove need to duplicate dependency definitions (i.e. injecting a config bean to all gateways [use parent bean instead])don’t have to write setters, just create a parent bean for gateways, have all gateways reference the parent bean.Factory Bean - create your own custom Factories, special kinds of objects that create and return other objectsAOP – Aspect Orientated Programming Kurt could probably give an entire talk on thisRemote Proxies - automatically generate Remote Proxy componentsyou can specify what components are open for remote access, as well as which methods are exposedMock Objects – testingFactory-post-processors:Tony Nelson - has done some cool things with post-processorsi.e. Annotation-base Dependency injectionlooks at all the beans defined in ColdSpring, checks their metadata for a "beans" attribute inside the cfcomponent tag, and automatically injects the requested beans into the component inside a variables.beansstruct.
Dependency Injection/Inversion of Control (summarizedfrom reference guide)• components aren't asked to do things outside of their scope or duty (known as "separation of concerns") • components aren't completely tied to other implementations (again, less coupling) • components are easier to configure and you can do so without changing code Introduction • components become easier to test (we can dictate which collaborators they use, perhaps even creating dummy "stub" or "mock" objects to trick the component into thinking that it's running in a different environment). • you can get a birds eye view of the dependencies among your components (and generate some neat documentation) • components are not tied to ColdSpring at all. There should be very little plumbing required to use ColdSpring in any environment, and only "calling" code will be aware of its existence. In Model-View-Controller apps, this usually means that the Controller will have some knowledge of ColdSpring but nothing else will