tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Tapestry > Aliases
Date Tue, 29 Jun 2010 08:00:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/8/_/styles/combined.css?spaceKey=TAPESTRY&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/TAPESTRY/Aliases">Aliases</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~uli">Ulrich
Stärk</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{deprecated:since=5.2|title=Use</span>
<span class="diff-added-words"style="background-color: #dfd;">{deprecated:since=5.2|message=Use</span>
ServiceOverrides instead}{deprecated} <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{deprecated:since=5.2}
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        
<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Deprecated
since 5.2</b><br />Use ServiceOverrides instead</td></tr></table></div>

<div style="border-right: 20px solid #ffcccc;border-left: 20px solid #ffcccc;">
$body
</div>



<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Deprecated
since 5.2</b><br /></td></tr></table></div>

<div style="border-right: 20px solid #ffcccc;border-left: 20px solid #ffcccc;">

<h1><a name="Aliases-Introduction"></a>Introduction</h1>

<p>Tapestry goes to great lengths so that you can use the <a href="#Aliases-inject.html">Inject</a>
annotation on a field and provide no additional data, yet end up with the correct object or
service.</p>

<p>In many cases, Tapestry must match a field type to an available IoC service.</p>

<p>If there is only single service in the registry that implements the service, Tapestry
will utilize that service.</p>

<p>When there is more than one such service, it is necessary to disambiguate which service
is to be injected. To disambiguate globally (across all injections), you must create an alias
from the service interface directly to the particular service.</p>

<p>This takes the form of a contribution to the Alias service.</p>

<p>The Alias service has additional purposes: first, it allows for spot overrides on
injected services, based on the application's mode. Currently, the only mode is "servlet",
but future modes may include "portlet" and possibly "offline".</p>

<p>Secondly, the companion AliasOverrides service configuration allows for spot overrides
of specific services, without disturbing the rest of the network of services within the IoC
Registry.</p>
</div>


<h1><a name="Aliases-ContributinganAlias"></a>Contributing an Alias</h1>

<p>To contribute a new service to the Alias service, you must first decide on a logical
name. Often, this is the name of the service interface implemented by the service.</p>

<p>You can then contribute into the Infrastructure service's configuration:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  <span class="code-keyword">public</span> <span class="code-keyword">static</span>
void contributeAlias(@InjectService(<span class="code-quote">"MyService"</span>)
MyService myService,
     Configuration&lt;AliasContribution&gt; configuration)
  {
     configuration.add(AliasContribution.create(MyService.class, myService));
  }
</pre>
</div></div>

<p>The above example follows a typical pattern; the service to be vended is injected
into the contributor method, using the explicit InjectService annotation. A contribution is
made providing the service type.</p>

<p>Notice that the contribution doesn't <em>have</em> to be a service; you
can just instantiate an object inside the contribution method and contribute that. That's
what we're doing in the example, though we're using a create() static method rather than <b>new</b>
(just to smooth out some Java Generics ugliness).</p>

<h1><a name="Aliases-ContributingtoAliasOverrides"></a>Contributing to AliasOverrides</h1>

<p>To override a service, you need to know its service interface name.</p>

<p>You can then make a contribution to the AliasOverrides service configuration, as
described in the previous section.</p>

<p>The object contributed as an override will mask the default contribution.</p>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/TAPESTRY/Aliases">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=21792138&revisedVersion=7&originalVersion=6">View
Changes</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message