Dependency Injection is a software design pattern in which classes are written expecting to be told about their dependencies instead of containing code to resolve them on their own. Some typical examples of this sort of dependency resolving code include:
  • Creating instances in a constructor or "init" method
  • Reading config files
  • Reading configuration data from a web service or database
  • Accessing global variables (or static variables)

All of these methods of resolving dependencies have one or more of the following problems:
  • Creates tight coupling between the class and the specific implementation of an interface
  • Creates tight coupling between the class and a remote resource
  • Creates tight coupling between the class and the file system
  • Makes it more difficult or impossible to isolate the class for testing
  • Makes it difficult to change the number of instances of a given class (especially changing from a singleton to multiple instances)

Anise is a framework which helps you implement the Dependency Injection pattern by making it easy to:
  • Write each class with constructors and properties for accepting dependencies instead of code to resolve dependencies on their own
  • Introduce dependencies into each class using a simple configuration file
  • Configure any object using any constructor, property or method with no extra boilerplate
  • Radically reconfigure your program using a simple configuration file
  • Isolate any class for unit testing and provide stub objects

If you're familiar with other Dependency Injection frameworks (e.g., Unity, Spring, etc.), here are some of the major differences between Anise and other frameworks:
  • Anise uses an extremely simple language (similar to JSON) for specifying configuration files instead of XML.
  • Anise allows objects to be declared inline anywhere a value is expected
  • Anise allows any object to be referenced from anywhere in a configuration script
  • Anise allows any script to be included from another script (similar to #include in C)
  • Anise allows injection by constructors, properties, or methods
  • Anise allows any property or method to be injected multiple times on the same object
  • Anise provides detailed error messages including file, line number, and position for any exceptions
  • Anise comes with a command-line program to either run your scripts, or to serve as an interactive shell
  • Anise supports being embedded inside another program, and can use embedded resources for configuration scripts
  • Read the User's Guide in the documentation section for more details!

Last edited Jun 27, 2010 at 7:18 PM by aminer, version 4