Update reference documentation generation tools to get source highlighting [SPRNET-1045]
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
<chapter id="quickstarts">
|
||||
<chapter xml:id="quickstarts" xmlns="http://docbook.org/ns/docbook" version="5">
|
||||
<title>IoC Quickstarts</title>
|
||||
|
||||
<sect1>
|
||||
@@ -26,7 +26,7 @@
|
||||
the Spring.NET framework.</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="qs-moviefinder">
|
||||
<sect1 xml:id="qs-moviefinder">
|
||||
<title>Movie Finder</title>
|
||||
|
||||
<para>The source material for this simple demonstration of Spring.NET's
|
||||
@@ -65,12 +65,12 @@
|
||||
</imageobject>
|
||||
</mediaobject></para>
|
||||
|
||||
<sect2 id="qs-mf-gettingstarted">
|
||||
<sect2 xml:id="qs-mf-gettingstarted">
|
||||
<title>Getting Started - Movie Finder</title>
|
||||
|
||||
<para>The startup class for the MovieFinder example is the
|
||||
<literal>MovieApp</literal> class, which is an ordinary .NET class with
|
||||
a single application entry point... <programlisting>using System;
|
||||
a single application entry point... <programlisting language="csharp">using System;
|
||||
namespace Spring.Examples.MovieFinder
|
||||
{
|
||||
public class MovieApp
|
||||
@@ -91,7 +91,7 @@ namespace Spring.Examples.MovieFinder
|
||||
custom configuration section in a standard .NET application config
|
||||
file...</para>
|
||||
|
||||
<programlisting><?xml version="1.0" encoding="utf-8" ?>
|
||||
<programlisting language="myxml"><?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="spring">
|
||||
@@ -115,7 +115,7 @@ namespace Spring.Examples.MovieFinder
|
||||
|
||||
<para>The body of the <literal>Main</literal> method in the
|
||||
<literal>MovieApp</literal> class can now be fleshed out a little
|
||||
further... <programlisting>
|
||||
further... <programlisting language="csharp">
|
||||
using System;
|
||||
using Spring.Context;
|
||||
...
|
||||
@@ -129,14 +129,14 @@ using Spring.Context;
|
||||
<literal>Spring.Context</literal> namespace gives the application access
|
||||
to the <literal>IApplicationContext</literal> class that will serve as
|
||||
the primary means for the application to access the IoC container. The
|
||||
line of code... <programlisting>IApplicationContext ctx = ContextRegistry.GetContext();</programlisting>
|
||||
line of code... <programlisting language="csharp">IApplicationContext ctx = ContextRegistry.GetContext();</programlisting>
|
||||
... retrieves a fully configured <literal>IApplicationContext</literal>
|
||||
implementation that has been configured using the named
|
||||
<literal><objects/></literal> section from the application config
|
||||
file.</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="qs-mf-firstobject">
|
||||
<sect2 xml:id="qs-mf-firstobject">
|
||||
<title>First Object Definition</title>
|
||||
|
||||
<para>As yet, no objects have been defined in the application config
|
||||
@@ -144,7 +144,7 @@ using Spring.Context;
|
||||
<literal>MovieLister</literal> instance that we are going to use in the
|
||||
application can be seen in the following XML snippet...</para>
|
||||
|
||||
<programlisting><objects xmlns="http://www.springframework.net">
|
||||
<programlisting language="myxml"><objects xmlns="http://www.springframework.net">
|
||||
<object name="MyMovieLister"
|
||||
type="Spring.Examples.MovieFinder.MovieLister, Spring.Examples.MovieFinder">
|
||||
</object>
|
||||
@@ -158,7 +158,7 @@ using Spring.Context;
|
||||
object so defined can be retrieved from the
|
||||
<literal>IApplicationContext</literal> reference like so...</para>
|
||||
|
||||
<programlisting>...
|
||||
<programlisting language="csharp">...
|
||||
public static void Main ()
|
||||
{
|
||||
IApplicationContext ctx = ContextRegistry.GetContext();
|
||||
@@ -177,21 +177,21 @@ using Spring.Context;
|
||||
injected into the <literal>lister</literal> instance looks like
|
||||
this...</para>
|
||||
|
||||
<programlisting><objects xmlns="http://www.springframework.net">
|
||||
<programlisting language="myxml"><objects xmlns="http://www.springframework.net">
|
||||
<object name="MyMovieFinder"
|
||||
type="Spring.Examples.MovieFinder.SimpleMovieFinder, Spring.Examples.MovieFinder"/>
|
||||
</object>
|
||||
</objects></programlisting>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="qs-mf-setterinjection">
|
||||
<sect2 xml:id="qs-mf-setterinjection">
|
||||
<title>Setter Injection</title>
|
||||
|
||||
<para>What we want to do is inject the <literal>IMovieFinder</literal>
|
||||
instance identified by the <literal>MyMovieFinder</literal> id into the
|
||||
<literal>MovieLister</literal> instance identified by the
|
||||
<literal>MyMovieLister</literal> id, which can be accomplished using
|
||||
Setter Injection and the following XML... <programlisting><objects xmlns="http://www.springframework.net">
|
||||
Setter Injection and the following XML... <programlisting language="myxml"><objects xmlns="http://www.springframework.net">
|
||||
<object name="MyMovieLister"
|
||||
type="Spring.Examples.MovieFinder.MovieLister, Spring.Examples.MovieFinder">
|
||||
<!-- using setter injection... -->
|
||||
@@ -210,7 +210,7 @@ using Spring.Context;
|
||||
<literal>MovieLister</literal> object that is referenced in the
|
||||
application is then fully configured and ready to be used in the
|
||||
application to do what is does best... list movies by director.
|
||||
<programlisting>...
|
||||
<programlisting language="csharp">...
|
||||
public static void Main ()
|
||||
{
|
||||
IApplicationContext ctx = ContextRegistry.GetContext();
|
||||
@@ -235,12 +235,12 @@ using Spring.Context;
|
||||
the reference documentation.</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="qs-mf-constructorinjection">
|
||||
<sect2 xml:id="qs-mf-constructorinjection">
|
||||
<title>Constructor Injection</title>
|
||||
|
||||
<para>Let's define another implementation of the
|
||||
<literal>IMovieFinder</literal> interface in the application config
|
||||
file...<programlisting>...
|
||||
file...<programlisting language="myxml">...
|
||||
<object name="AnotherMovieFinder"
|
||||
type="Spring.Examples.MovieFinder.ColonDelimitedMovieFinder, Spring.Examples.MovieFinder">
|
||||
</object>
|
||||
@@ -248,18 +248,18 @@ using Spring.Context;
|
||||
<literal>IMovieFinder</literal> implementation that uses a colon
|
||||
delimited text file as it's movie source. The C# source code for this
|
||||
class defines a single constructor that takes a
|
||||
<classname>System.IO.FileInfo</classname> as it's single constructor
|
||||
<literal>System.IO.FileInfo</literal> as it's single constructor
|
||||
argument. As this object definition currently stands, attempting to get
|
||||
this object out of the <literal>IApplicationContext</literal> in the
|
||||
application with a line of code like so... <programlisting>IMovieFinder finder = (IMovieFinder) ctx.GetObject ("AnotherMovieFinder");</programlisting>
|
||||
application with a line of code like so... <programlisting language="csharp">IMovieFinder finder = (IMovieFinder) ctx.GetObject ("AnotherMovieFinder");</programlisting>
|
||||
will result in a fatal
|
||||
<classname>Spring.Objects.Factory.ObjectCreationException</classname>,
|
||||
<literal>Spring.Objects.Factory.ObjectCreationException</literal>,
|
||||
because the
|
||||
<classname>Spring.Examples.MovieFinder.ColonDelimitedMovieFinder</classname>
|
||||
<literal>Spring.Examples.MovieFinder.ColonDelimitedMovieFinder</literal>
|
||||
class does not have a default constructor that takes no arguments. If we
|
||||
want to use this implementation of the <literal>IMovieFinder</literal>
|
||||
interface, we will have to supply an appropriate constructor
|
||||
argument...<programlisting>...
|
||||
argument...<programlisting language="myxml">...
|
||||
<object name="AnotherMovieFinder"
|
||||
type="Spring.Examples.MovieFinder.ColonDelimitedMovieFinder, Spring.Examples.MovieFinder">
|
||||
<constructor-arg index="0" value="movies.txt"/>
|
||||
@@ -269,11 +269,11 @@ using Spring.Context;
|
||||
<para>Unsurprisingly, the <constructor-arg/> element is used to
|
||||
supply constructor arguments to the constructors of managed objects. The
|
||||
Spring.NET IoC container uses the functionality offered by
|
||||
<classname>System.ComponentModel.TypeConverter</classname>
|
||||
<literal>System.ComponentModel.TypeConverter</literal>
|
||||
specializations to convert the <literal>movies.txt</literal> string into
|
||||
an instance of the <classname>System.IO.FileInfo</classname> that is
|
||||
an instance of the <literal>System.IO.FileInfo</literal> that is
|
||||
required by the single constructor of the
|
||||
<classname>Spring.Examples.MovieFinder.ColonDelimitedMovieFinder</classname>
|
||||
<literal>Spring.Examples.MovieFinder.ColonDelimitedMovieFinder</literal>
|
||||
(see <xref linkend="objects-objects-conversion" /> for a more in depth
|
||||
treatment concerning the automatic type conversion functionality offered
|
||||
by Spring.NET).</para>
|
||||
@@ -283,7 +283,7 @@ using Spring.Context;
|
||||
distinct object definitions in the config file of the example
|
||||
application; if we wanted to, we could switch the implementation that
|
||||
the <literal>MyMovieLister</literal> object uses like
|
||||
so...<programlisting>...
|
||||
so...<programlisting language="myxml">...
|
||||
<object name="MyMovieLister"
|
||||
type="Spring.Examples.MovieFinder.MovieLister, Spring.Examples.MovieFinder">
|
||||
<!-- lets use the colon delimited implementation instead -->
|
||||
@@ -306,7 +306,7 @@ using Spring.Context;
|
||||
<literal>MyMovieLister</literal> object.</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="qs-mf-summary">
|
||||
<sect2 xml:id="qs-mf-summary">
|
||||
<title>Summary</title>
|
||||
|
||||
<para>This example application is quite simple, and admittedly it
|
||||
@@ -345,8 +345,8 @@ using Spring.Context;
|
||||
log4net in your main application, declare some loggers in code, and then
|
||||
log log log. (Sing along...) We are using App.config to configure the
|
||||
loggers. As such, we declare the log4net configuration section handler
|
||||
as shown below <programlisting><section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /></programlisting>
|
||||
The corresponding configuration section looks like this <programlisting>
|
||||
as shown below <programlisting language="myxml"><section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /></programlisting>
|
||||
The corresponding configuration section looks like this <programlisting language="myxml">
|
||||
<log4net>
|
||||
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
@@ -379,7 +379,7 @@ using Spring.Context;
|
||||
<para>The logging name is up to you to decide when you declare the
|
||||
logger in code. In the case of this example we used the convention of
|
||||
giving the logging name the name of the fully qualified class name.
|
||||
<programlisting>private static readonly ILog LOG = LogManager.GetLogger(typeof (MovieApp));</programlisting>
|
||||
<programlisting language="csharp">private static readonly ILog LOG = LogManager.GetLogger(typeof (MovieApp));</programlisting>
|
||||
Other conventions are to give the same logger name across multiple
|
||||
classes that constitute a logical component or subsystem within the
|
||||
application, for example a data access layer. One tip in selecting the
|
||||
@@ -390,7 +390,7 @@ using Spring.Context;
|
||||
format %logger{2}.</para>
|
||||
|
||||
<para>To initialize the logging system add the following to the start of
|
||||
your application <programlisting>XmlConfigurator.Configure();</programlisting>
|
||||
your application <programlisting language="csharp">XmlConfigurator.Configure();</programlisting>
|
||||
Note that if you are using or reading information on version 1.2.0 this
|
||||
used to be called DOMConfigurator.Configure();</para>
|
||||
|
||||
@@ -406,9 +406,9 @@ using Spring.Context;
|
||||
objects. Coincidentally, the example code itself uses Spring in the
|
||||
logger name, so this logger also controls the output level you see from
|
||||
running MainApp. Finally, you are ready to use the simple logger api to
|
||||
log, i.e. <programlisting>LOG.Info("Searching for movie...");</programlisting>
|
||||
log, i.e. <programlisting language="csharp">LOG.Info("Searching for movie...");</programlisting>
|
||||
Logging exceptions is another common task, which can be done using the
|
||||
error level <programlisting>try {
|
||||
error level <programlisting language="csharp">try {
|
||||
//do work
|
||||
{
|
||||
catch (Exception e)
|
||||
@@ -418,7 +418,7 @@ catch (Exception e)
|
||||
</sect2>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="qs-appcontext-messagesource">
|
||||
<sect1 xml:id="qs-appcontext-messagesource">
|
||||
<title>ApplicationContext and IMessageSource</title>
|
||||
|
||||
<sect2>
|
||||
@@ -453,7 +453,7 @@ catch (Exception e)
|
||||
to the ResourceManager in other parts of your application. In the
|
||||
example program an embedded resource file, MyResource.resx and a Spanish
|
||||
specific resource file, MyResources.es.resx are declared in this manner.
|
||||
The corresponding XML fragment is shown below <programlisting>...
|
||||
The corresponding XML fragment is shown below <programlisting language="myxml">...
|
||||
<object name="messageSource" type="Spring.Context.Support.ResourceSetMessageSource, Spring.Core">
|
||||
<property name="resourceManagers">
|
||||
<list>
|
||||
@@ -484,7 +484,7 @@ catch (Exception e)
|
||||
contains a text resource, <literal>Hello {0} {1}</literal> under the key
|
||||
name <literal>HelloMessage</literal> (aka Keys.HELLO_MESSAGE) that can
|
||||
be used for string text formatting purposes. The example code
|
||||
<programlisting>
|
||||
<programlisting language="csharp">
|
||||
string msg = ctx.GetMessage(Keys.HELLO_MESSAGE,
|
||||
CultureInfo.CurrentCulture,
|
||||
"Mr.", "Anderson");
|
||||
@@ -492,7 +492,7 @@ string msg = ctx.GetMessage(Keys.HELLO_MESSAGE,
|
||||
the string with the passed argument values resulting in the text, "Hello
|
||||
Mr. Anderson". The current culture is used to select the resource file
|
||||
MyResource.resx. If instead the Spanish culture is specified
|
||||
<programlisting>
|
||||
<programlisting language="csharp">
|
||||
CultureInfo spanishCultureInfo = new CultureInfo("es");
|
||||
string esMsg = ctx.GetMessage(Keys.HELLO_MESSAGE,
|
||||
spanishCultureInfo,
|
||||
@@ -510,7 +510,7 @@ string esMsg = ctx.GetMessage(Keys.HELLO_MESSAGE,
|
||||
into a key of its own, called <literal>FemaleGreeting</literal> (aka
|
||||
Keys.FEMALE_GREETING). The replacement value for the message argument
|
||||
{0} can then be made localization aware by wrapping the key in a
|
||||
convenience class DefaultMessageResolvable. The code <programlisting>
|
||||
convenience class DefaultMessageResolvable. The code <programlisting language="csharp">
|
||||
string[] codes = {Keys.FEMALE_GREETING};
|
||||
DefaultMessageResolvable dmr = new DefaultMessageResolvable(codes, null);
|
||||
|
||||
@@ -519,7 +519,7 @@ msg = ctx.GetMessage(Keys.HELLO_MESSAGE,
|
||||
dmr, "Anderson");
|
||||
</programlisting> will assign msg the value, Hello Mrs. Anderson, since the
|
||||
value for the key <literal>FemaleGreeting</literal> in MyResource.resx
|
||||
is 'Mrs.' Similarly, the code <programlisting>
|
||||
is 'Mrs.' Similarly, the code <programlisting language="csharp">
|
||||
esMsg = ctx.GetMessage(Keys.HELLO_MESSAGE,
|
||||
spanishCultureInfo,
|
||||
dmr, "Anderson");
|
||||
@@ -536,7 +536,7 @@ esMsg = ctx.GetMessage(Keys.HELLO_MESSAGE,
|
||||
property Name. The resource file, Person.resx contains key names that
|
||||
follow the pattern, person.<PropertyName>. In this case it
|
||||
contains person.Name and person.Age. The code to assign these resource
|
||||
values to an object is shown below <programlisting>
|
||||
values to an object is shown below <programlisting language="csharp">
|
||||
Person p = new Person();
|
||||
ctx.ApplyResources(p, "person", CultureInfo.CurrentUICulture);
|
||||
</programlisting> While you could also use the Spring itself to set the
|
||||
|
||||
Reference in New Issue
Block a user