tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Tapestry > IoC - run
Date Fri, 01 Oct 2010 11:41:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/12/_/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/IoC+-+run">IoC
- run</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~ccordenier">Christophe
Cordenier</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >The call to performRegistryStartup()
is necessary to ensure that any services marked with the [EagerLoad|../apidocs/org/apache/tapestry5/ioc/annotations/EagerLoad.html]
annotation are, in fact, loaded. <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{info:title=Since
5.2}{info} <br>As of version 5.2 the class [RegistryBuilder|../apidocs/org/apache/tapestry5/ioc/RegistryBuilder.html]
has convenience methods to build and start a Registry. The static method [RegistryBuilder.buildAndStartupRegistry(Class...)|../apidocs/org/apache/tapestry5/ioc/RegistryBuilder.html#buildAndStartupRegistry(java.lang.Class...)]
constructs a registry, adds a number of modules to the registry and performs registry startup.
The returned registry is ready to use. <br> <br>{code:java} <br>Registry
registry = RegistryBuilder.buildAndStartupRegistry(AppModule.class, UtilModule.class); <br>{code}
<br> <br></td></tr>
            <tr><td class="diff-unchanged" >h1. Building the Default Registry
<br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="IoC-run-StartingtheTapestryIoCRegistry"></a>Starting
the Tapestry IoC Registry</h1>

<p>Primarily, you will use the IoC Registry as part of a Tapestry application. In those
situations, the <span class="error">&#91;TapestryFilter|../apidocs/org/apache/tapestry5/TapestryFilter.html&#93;</span>
will be responsible for starting and stopping the registry.</p>

<p>However, you may want to do some integration testing using the Registry from within
a test case, or you may even use Tapestry IoC separately from Tapestry.</p>

<h1><a name="IoC-run-BuildingtheRegistry"></a>Building the Registry</h1>

<p>The class <span class="error">&#91;RegistryBuilder|../apidocs/org/apache/tapestry5/ioc/RegistryBuilder.html&#93;</span>
is used to create a Registry.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RegistryBuilder builder = <span class="code-keyword">new</span> RegistryBuilder();

builder.add(AppModule.class, UtilModule.class);

Registry registry = builder.build();

registry.performRegistryStartup();</pre>
</div></div>

<p>You may invoke add() as many times as you wish, or pass as many module classes as
you wish.</p>

<p>Using this approach, you will form a Registry containing the builtin services from
the <span class="error">&#91;Tapestry IoC module|../apidocs/org/apache/tapestry5/ioc/services/TapestryIoCModule.html&#93;</span>,
plus the modules you explicitly list.</p>

<p>The call to performRegistryStartup() is necessary to ensure that any services marked
with the <span class="error">&#91;EagerLoad|../apidocs/org/apache/tapestry5/ioc/annotations/EagerLoad.html&#93;</span>
annotation are, in fact, loaded.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Since 5.2</b><br
/></td></tr></table></div>
<p>As of version 5.2 the class <span class="error">&#91;RegistryBuilder|../apidocs/org/apache/tapestry5/ioc/RegistryBuilder.html&#93;</span>
has convenience methods to build and start a Registry. The static method <span class="error">&#91;RegistryBuilder.buildAndStartupRegistry(Class...)|../apidocs/org/apache/tapestry5/ioc/RegistryBuilder.html#buildAndStartupRegistry(java.lang.Class...)&#93;</span>
constructs a registry, adds a number of modules to the registry and performs registry startup.
The returned registry is ready to use.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Registry registry = RegistryBuilder.buildAndStartupRegistry(AppModule.class, UtilModule.class);
</pre>
</div></div>

<h1><a name="IoC-run-BuildingtheDefaultRegistry"></a>Building the Default
Registry</h1>

<p>The default registry is available by invoking the static method <span class="error">&#91;IOCUtilities.buildDefaultRegistry()|../apidocs/org/apache/tapestry5/ioc/IOCUtilities.html#buildDefaultRegistry&#93;</span>.
This method builds a Registry using <a href="#IoC-run-autoload.html">autoloading logic</a>,
where modules to load are identified via a JAR Manifest entry.</p>

<p>In addition, the JVM system property <tt>tapestry.modules</tt> (if specified)
is a list of additional module classes to load. This is often used in development, where tests
may be executed against the local classes, not JARs, and so there no manifest to read.</p>

<h1><a name="IoC-run-ShuttingdowntheRegistry"></a>Shutting down the Registry</h1>

<p>The method <span class="error">&#91;Registry.shutdown()|../apidocs/org/apache/tapestry5/ioc/Registry.html#shutdown&#93;</span>
will shutdown the Registry. This immediately invalidates all service proxies. Some services
may have chosen to register for shutdown notification (for example, to do cleanup work such
as closing a database connection).</p>

<p>Once the Registry is shutdown, it may not be used again: it will not be possible
to access services within the Registry, or invoke methods on services previously acquired.
All you can do is release the Registry to the garbage collector.</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/IoC+-+run">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=23338490&revisedVersion=2&originalVersion=1">View
Changes</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message