Sitting in on Dave Ross's Inversion of Control (ColdSpring) presentation right now. Dave's laying the groundwork for the "what & why" of ColdSpring. For background, it's a framework, but not one like ModelGlue, Fusebox, Mach-II, etc. It's more like a container for your application's model. It doesn't handle HTTP requests. It's based off of the Java Spring framework, but it's not a one-for-one port. It attempts to solve the same problems, though.

ColdSpring implements a flexible model, where components use each other (one component depends on another to do work), as opposed to one component creating and configuring another. This is called a dependency, with the two components being collaborators. As an IoC container, ColdSpring injects one component into another. Components don't have to create and configure each other - they just use each other. This also makes the actual implementation unimportant as you are now programming to an interface.

Polymorphism - you can swap out one implementation of a component for another and collaborators don't know the difference.

ColdSpring works like this:

  1. Create an xml file that defines the components and their configs
  2. Refer to the content as bean definitions of bean defs - bean is interchangeable with component
  3. Create a ColdSpring BeanFactory and then pass in your bean definitions

How does ColdSpring get used in a real app:

  1. When app starts, BeanFactory is created and supplied with bean defs
  2. BeanFactory is placed in a persistent scope (application) so that the beans are singletons
  3. In an MVC app, the controller obtains the component(s) it needs from the BeanFactory
  4. ColdSpring is not usually involved with the creation of transient or value objects because that requires knowledge of the framework by other components. The main idea here is that your model shouldn't know it's being managed by ColdSpring.

BeanFactory can also do auto-wiring. Lets ColdSpring automatically figure out which components should be injected where by looking at the method signatures of the defined components and matching with bean definitions. There are pros and cons to auto-wiring. Pros are less typing and less xml. Cons are having to keep better track of what's going on.

ColdSpring AOP (aspect oriented programming). It allows you to apply a piece of code across the rest of your codebase in logical places - such as before or after a method call or when an exception is thrown. AOP is often used in logging and security, but it isn't limited to that. It also works well for managing transactions and workflow. ColdSpring AOP can also be used to expose functionality to services such as Flash Remoting without having to create a facade. Chris Scott programmed the AOP piece of ColdSpring.

ModelGlue 2.0 uses ColdSpring as the default IoC container. It's used by the framework itself and is also exposed so you can use it.

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)



Copyright 1995-2010 Rob Brooks-Bilson. All rights reserved.
Aura skin for Raymond Camden's BlogCFC inspired by Joe Rinehart & Steven Erat. This blog is running version 5.9.004.