<?xml version="1.0"?>
<!-- 
   Copyright 2004, 2005 The Apache Software Foundation

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->

<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.3//EN"
	"http://xml.apache.org/forrest/dtd/document-v13.dtd" [
	<!ENTITY % common-links SYSTEM "links.ent">
	%common-links;
	]>
<document>
	<header>
		<title>Inversion of Control</title>
	</header>
	<body>
		<p>Seems like <fork
			href="http://excalibur.apache.org/framework/guide-patterns-ioc.html"><strong>
			Inversion of Control</strong></fork> is all the rage these days. The <fork
			href="http://excalibur.apache.org/">Apache Excalibur</fork> project is completely based
			around it. Excalibur uses detailed assembly descriptions to tie services
			together ... there's no way an Excalibur component can "look up" another
			component; in Excalibur you explicitly connect services together.</p>
		<p>That's the basic concept of Inversion of Control; you don't create your
			objects, you describe how they should be created. You don't directly
			connect your components and services together in code, you describe which
			services are needed by which components, and the container is responsible
			for hooking it all together. The container creates all the objects, wires
			them together by setting the necessary properties, and determines when
			methods are invoked.</p>
		<p>More recently, this concept has been renamed <fork
			href="http://www.martinfowler.com/articles/injection.html">Dependency
			Injection</fork>.</p>
		<p>There are three different implementation pattern types for IoC:</p>
		<table>
			<tr>
				<td>type-1</td>
				<td>Services need to implement a dedicated interface through which they
					are provided with an object from which they can look up dependencies
					(other services). This is the pattern used by the earlier containers
					provided by Excalibur.</td>
			</tr>
			<tr>
				<td>type-2</td>
				<td>Services dependencies upon are assigned via JavaBeans properties
					(setter methods). Both HiveMind and  &Spring;
					 use this approach.</td>
			</tr>
			<tr>
				<td>type-3</td>
				<td>Services dependencies are provided as constructor parameters (and
					are not exposed as JavaBeans properties). This is the exclusive
					approach used by <fork href="http://www.picocontainer.org/">
					PicoContainer</fork>, and is also used in HiveMind and Spring.</td>
			</tr>
		</table>
		<p>HiveMind is a much looser system than Excalibur. HiveMind doesn't have an
			explicit assembly stage; it wires together all the modules it can find at
			runtime. HiveMind is responsible for creating services (including core
			implementations and interceptors). It is quite possible to create service
			factories that do very container-like things, including connecting
			services together. &hivemind.BuilderFactory; does just that, instantiating
			an object to act as the core service implementation, then setting
			properties of the object, some of which are references to services and
			configuration point element data.</p>
		<p>In HiveMind, you are free to mix and match type-2 (property injection)
			and type-3 (constructor injection), setting some (or all) dependencies via
			a constructor and some (or all) via JavaBeans properties.</p>
		<p>In addition, JavaBeans properties (for dependencies) can be write-only.
			You only need to provide a setter method. The properties are properties of
			the core service implementation, there is no need for the accessor methods
			to be part of the service interface.</p>
		<p>HiveMind's lifecycle support is much more rudimentary than Excalibur's. Your
			service implementations can get hivemindcallbacks when they are first
			created, and when they are discarded, by implementing certain interfaces.</p>
		<p>Purist inversion of control, as in Excalibur, may be more appropriate in
			well-constrained systems containing untrusted code. HiveMind is a layer
			below that, not an application server, but a microkernel. Although I can
			see using HiveMind as the infrastructure of an application server, even an
			Excalibur application server, it doesn't directly overlap otherwise.</p>
	</body>
</document>
