NanoContainer.NET
So what is NanoContainer? NanoContainer is a complimentary API for defining PicoContainers.
The NanoContainer.NET (or Nano.NET for short) implementation differs slightly from what has been developed for the Java implementation. Nano.NET takes advantage of the System.CodeDom Library for .NET to dynamically compile Nano scripts. And the XML implementation dynamically generates C# code from the XML script defined.
Comparison of NanoContainer for Java with NanoContainer.NET
This section is useful for those familiar with the Java implementation of NanoContainer. An example of the differences are defined below.
NanoContainer for Java
NanoContainer for Java relies on creating an API that is similar in nature to that of PicoContainer but based solely on the use of Strings. From a highlevel view, a script is parsed and components are added to an instance of NanoContainer by its String representation (i.e. "foo.bar.HelloWorld").
NanoContainer.NET
The Nano.NET implementation does not require the use of a concrete NanoContainer class. Scripts are loaded and executed dynamically. There is no need for an intermediate step to parse each script into an instance of a NanoContainer. The result of running a NanoContainer script is an instance of PicoContainer.IPicoContainer.
I want to see an example!
So for the impatient lets take a quick look at how we would utilize Nano.NET. The following script registers an implementation (bar.Foo) under the key "hello".
Now there are 2 important things to notice with the above example.
- A setter Property named
Parent - The method
public IMutablePicoContainer Compose()
These are both requirements of any script that will be written. In other words every script written for NanoContainer.NET must have the equivalent Property and Method defined (this of course will vary based on the scripting language used).
It is also possible to define your script as an implementation of the NanoContainer.Script.IScript Interface. This interface defines both the Parent property and the Compose method. Regardless of whether your script implements the IScript interface NanoContainer will treat your script it as an instance of IScript.
| Remember The purpose of a script is that it can be referenced, compiled and executed at Runtime not at Compile time. So if your script does not implement the |
Now that we have a script defined we need to load the script so it can be used by NanoContainer.NET. The following example shows the necessary code needed to load the script and build the associated container
What languages can be used for scripting?
- C#
- Boo
- Visual Basic
- JScript
- J#
- XML
NanoContainer.NET also supports .NET Attributes for defining contents of a container but then that really doesn't fit under the "Scripts" definition and therefor not listed as a scripting option.
