|
|||||
|
|||||
XML Script Example
Here is an example of how to write and use a NanoContainer.NET script written in XML. The code below demonstrates how to registered classes with the Container through NanoContainer.NET Xml scripts. As with the Attributes Usage Example the MovieFinder and MovieLister example Martin Fowler described in his article Inversion of Control Containers and the Dependency Injection pattern is utilized for this Xml script example. The XML Script<container> <assemblies> <element file="MyNanoAssembly.dll"/> </assemblies> <component-implementation type="MovieLister"/> <component-implementation key="typeof(IMovieFinder)" type="ColonMovieFinder"> <parameter>"movies1.txt"</parameter> </component-implementation> </container> A few important comments on the above example:
For full details and examples of how to use the Xml syntax you would probably be best suited to look at the comprehensive test cases provided with NanoContainer.NET C# code to utilize XML scriptBootStrap.cs public class BootStrap { [STAThread] public static void Main() { Bootstrap bootstrap = new Bootstrap(); IPicoContainer picoContainer = bootstrap.Load(); ... } public IPicoContainer Load() { StreamReader streamReader= ...// load xml file ContainerBuilderFacade cbf = new XmlContainerBuilderFacade(streamReader); StringCollection assemblies = new StringCollection(); assemblies.Add("MyNanoAssembly.dll"); return cbf.Build(assemblies); } } |
|||||
|
Copyright 2003-2006 - The Codehaus. All rights reserved unless otherwise noted.
Powered by Atlassian Confluence
|
|||||