[CONF] Apache Tapestry IoC - injection

2010-12-28 Thread confluence







IoC - injection
Page moved by Bob Harner






From: 

Apache Tapestry
 Injection in Detail


To: 

Apache Tapestry
 Redirects





Children moved






   
Change Notification Preferences
   
   View Online
   









[CONF] Apache Tapestry IoC - injection

2010-12-22 Thread confluence







IoC - injection
Page  added by Bob Harner

 

 This page has been moved to Injection in Detail


   
Change Notification Preferences
   
   View Online
   








[CONF] Apache Tapestry IoC - injection

2010-11-23 Thread confluence







IoC - injection
Page edited by Howard M. Lewis Ship


 Changes (22)
 



...
Injection is triggered in a number of ways:  
* A field in a component class, autobuilt object, or service implementation class the [Inject|../apidocs/org/apache/tapestry5/ioc/annotations/Inject.html] [Inject|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html] annotation. 
* A method parameter to a service builder method, a decorator method, or a contribute method (in a Tapestry IoC module class). * A constructor parameter to an autobuilt object, or a service implementation class. 
* Any of the above with an [InjectService|../apidocs/org/apache/tapestry5/ioc/annotations/InjectService.html] [InjectService|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/InjectService.html] annotation. 
Injection also covers a related matter: providing special resources to a service or component. For a service, the services id (as a string) or extensible configuration (as a Collection, List or Map) may be provided. For a component, the components id, locale, message catalog, or component resources may be provided.  
...
 * org.slf4j.Logger The Logger of the service being constructed (or the logger of the Module class being instantiated). 
* [ObjectLocator|../apidocs/org/apache/tapestry5/ioc/ObjectLocator.html] [ObjectLocator|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/ObjectLocator.html] For contribute methods, used to locate additional objects. * [ServiceResources|../apidocs/org/apache/tapestry5/ioc/ServiceResources.html] [ServiceResources|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/ServiceResources.html] For service builder methods, an extended version of ObjectLocator. Class The service interface type. * [OperationTracker|../apidocs/org/apache/tapestry5/ioc/OperationTracker.html] [OperationTracker|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/OperationTracker.html] Used to track deeply nested operations so that errors can be reported sensibly. 
* Object, or service interface type Passed to decorator methods.  * Collection, List, Map Assembled service configurations passed to service builder methods (or service class constructors). * Configuration, OrderedConfiguration, MappedConfiguration Configuration passed to contribute methods, to build service configurations.If field type does not match any of the available resource types, or the Inject annotation is present, logic continues to the next step.  
Injection of resources into fields is triggered by the presence of the [InjectResource|../apidocs/org/apache/tapestry5/ioc/annotations/InjectResource.html] [InjectResource|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/InjectResource.html] annotation, whereas injection of resources into parameters occurs when the Inject or InjectService annotation is _not_ present. These rules are slightly tricky, which reflects a desire to avoid any annotations except when needed, and the fact that field injection came much later than parameter injection. 
 h2. Service Lookup by Type and Annotations 
...
First, it generates a set of services whose service interface is compatible with the injection type. This is based on assignability.  
If the [Local|../apidocs/org/apache/tapestry5/ioc/annotations/Local.html] [Local|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Local.html] annotation is present, then services not from the module containing the service being constructed will be eliminated. 
 Tapestry then works through the known marker annotations. For each marker annotation that is present at the point of annotation, Tapestry eliminates services which do not have the marker. Thus, if multiple marker annotations are present, the final service must have _all of them_. 
...
h2. MasterObjectProvider Lookup  
This is the point at which Tapestrys extensibility comes into play. MasterObjectProvider is a service, with a configuration of [ObjectProvider|../apidocs/org/apache/tapestry5/ioc/ObjectProvider.html]s. [ObjectProvider|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/ObjectProvider.html]s. 
 The MasterObjectProvider is also the point at which Tapestrys IoC layer injection, and Tapestrys component injection, unite. 
...
h3. Value ObjectProvider  
Checks for the presence of the [Value|../apidocs/org/apache/tapestry5/ioc/annotations/Value.html] [Value|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Value.html] annotation. If present, 

[CONF] Apache Tapestry IoC - injection

2010-11-23 Thread confluence







IoC - injection
Page edited by Howard M. Lewis Ship


 Changes (0)
 



...

Full Content

Injection in Detail

Injection in Tapestry IoC can be a complicated subject for a number of reasons:


	Injection can occur in many places: on fields, and on parameters to methods and constructors of certain objects.
	Parts of Injection are themselves defined in terms of Tapestry IoC services, many of which are extensible.



Despite this, injection generally Just Works: most of the time, you want Tapestry to inject a service, and only a single service implements the service interface.

This document discusses what to do when you hit a case that doesn't Just Work, or when you want to extend the injection logic in some way.

Some aspects of this discussion reflect Tapestry IoC used within a Tapestry web application: the tapestry-core module makes some extensions to injection.

Injection Triggers

Injection is triggered in a number of ways:


	A field in a component class, autobuilt object, or service implementation class the Inject annotation.
	A method parameter to a service builder method, a decorator method, or a contribute method (in a Tapestry IoC module class).
	A constructor parameter to an autobuilt object, or a service implementation class.
	Any of the above with an InjectService annotation.
Injection also covers a related matter: providing special resources to a service or component. For a service, the service's id (as a string) or extensible configuration (as a Collection, List or Map) may be provided. For a component, the component's id, locale, message catalog, or component resources may be provided.



Standard Injection Processing

This section describes standard injection, which applies at the IoC layer: autobuild objects and service implementations. The steps for injection into Tapestry components are slightly different and are covered later.

So a the point of injection, Tapestry has identified a field or parameter that should be injected. At this point, Tapestry knows the following:


	The field name (if field injection). The parameter name is not available.
	The field or parameter type, as a Java class. In many cases, this will be enough to identify what object shall be injected.
	Any additional annotations on the field or parameter.
Tapestry proceeds with this information.



Check for InjectService

Tapestry checks first for the InjectService annotation. The value of this annotation is the service id to inject. When InjectService is present at the point of injection, that process is done, though it can fail if the service id indicated does not exist, or if the service's interface is not compatible with the field's type.

Check for service resources

This step applies only to IoC layer injection (not to injection into components).

When the Inject annotation is not present at the point of injection, Tapestry checks to see if a resource can be injected. When the Inject annotation is present, this step is skipped (this is necessary when the object to be injected has a type that conflicts with a resource type, such as List or Class).


	org.slf4j.Logger The Logger of the service being constructed (or the logger of the Module class being instantiated).
	ObjectLocator For contribute methods, used to locate additional objects.
	ServiceResources For service builder methods, an extended version of ObjectLocator. Class The service interface type.
	OperationTracker Used to track deeply nested operations so that errors can be reported sensibly.
	Object, or service interface type Passed to decorator methods.
	Collection, List, Map Assembled service configurations passed to service builder methods (or service class constructors).
	Configuration, OrderedConfiguration, MappedConfiguration Configuration passed to contribute methods, to build service configurations.If field type does not match any of the available resource types, or the Inject annotation is present, logic continues to the next step.



Injection of resources into fields is triggered by the presence of the InjectResource annotation, whereas injection of resources into parameters occurs when the Inject or InjectService annotation is not present. These rules are slightly tricky, which reflects a desire to avoid any annotations except when needed, and the fact that field injection came much later than parameter injection.

Service Lookup by Type and Annotations

Tapestry attempts to find a matching service.

First, it generates a set of services whose service interface is compatible with the injection type. This is based on assignability.

If the Local annotation is present, then services not from the module containing the service being constructed will be eliminated.

Tapestry then works through the known marker annotations. For each marker annotation that is 

[CONF] Apache Tapestry IoC - injection

2010-09-20 Thread confluence







IoC - injection
Page  added by Ulrich Stärk

 

 Injection in Detail

Injection in Tapestry IoC can be a complicated subject for a number of reasons:


	Injection can occur in many places: on fields, and on parameters to methods and constructors of certain objects.
	Parts of Injection are themselves defined in terms of Tapestry IoC services, many of which are extensible.
Despite this, injection generally Just Works: most of the time, you want Tapestry to inject a service, and only a single service implements the service interface.



This document discusses what to do when you hit a case that doesn't Just Work, or when you want to extend the injection logic in some way.

Some aspects of this discussion reflect Tapestry IoC used within a Tapestry web application: the tapestry-core module makes some extensions to injection.

Injection Triggers

Injection is triggered in a number of ways:


	A field in a component class, autobuilt object, or service implementation class the Inject|../apidocs/org/apache/tapestry5/ioc/annotations/Inject.html annotation.
	A method parameter to a service builder method, a decorator method, or a contribute method (in a Tapestry IoC module class).
	A constructor parameter to an autobuilt object, or a service implementation class.
	Any of the above with an InjectService|../apidocs/org/apache/tapestry5/ioc/annotations/InjectService.html annotation.
Injection also covers a related matter: providing special resources to a service or component. For a service, the service's id (as a string) or extensible configuration (as a Collection, List or Map) may be provided. For a component, the component's id, locale, message catalog, or component resources may be provided.



Standard Injection Processing

This section describes standard injection, which applies at the IoC layer: autobuild objects and service implementations. The steps for injection into Tapestry components are slightly different and are covered later.

So a the point of injection, Tapestry has identified a field or parameter that should be injected. At this point, Tapestry knows the following:


	The field name (if field injection). The parameter name is not available.
	The field or parameter type, as a Java class. In many cases, this will be enough to identify what object shall be injected.
	Any additional annotations on the field or parameter.
Tapestry proceeds with this information.



Check for InjectService

Tapestry checks first for the InjectService annotation. The value of this annotation is the service id to inject. When InjectService is present at the point of injection, that process is done, though it can fail if the service id indicated does not exist, or if the service's interface is not compatible with the field's type.

Check for service resources

This step applies only to IoC layer injection (not to injection into components).

When the Inject annotation is not present at the point of injection, Tapestry checks to see if a resource can be injected. When the Inject annotation is present, this step is skipped (this is necessary when the object to be injected has a type that conflicts with a resource type, such as String).

 org.slf4j.Logger The Logger of the service being constructed (or the logger of the Module class being instantiated). String The service id of the service being constructed. ObjectLocator|../apidocs/org/apache/tapestry5/ioc/ObjectLocator.html For contribute methods, used to locate additional objects. ServiceResources|../apidocs/org/apache/tapestry5/ioc/ServiceResources.html For service builder methods, an extended version of ObjectLocator. Class The service interface type. OperationTracker|../apidocs/org/apache/tapestry5/ioc/OperationTracker.html Used to track deeply nested operations so that errors can be reported sensibly. Object, or service interface type Passed to decorator methods. Collection, List, Map Assembled service configurations passed to service builder methods (or service class constructors). Configuration, OrderedConfiguration, MappedConfiguration Configuration passed to contribute methods, to build service configurations.If field type does not match any of the available resource types, or the Inject annotation is present, logic continues to the next step.

Injection of resources into fields is triggered by the presence of the InjectResource|../apidocs/org/apache/tapestry5/ioc/annotations/InjectResource.html annotation, whereas injection of resources into parameters occurs when the Inject or InjectService annotation is not present. These rules are slightly tricky, which reflects a desire to avoid any annotations except when needed, and the fact that field injection came much later than parameter injection.

Service Lookup by Type and Annotations

Tapestry attempts to find a matching service.

First, it generates a set of services whose service interface is compatible with the injection type. This is based on assignability.

If