Overview
NanoWar is a NanoContainer component that brings the power of PicoContainer's Dependency Injection to the Java Servlet/Web application world.
Embedding NanoWar in a Web application
NanoWar allows to embed Container in a Java Servlet container.
NanoWar is non-intrusively activated in a Web application via a Servlet container event listener, configured in the web.xml.
Activation of Application and Session scope containers
<listener> <listener-class>org.nanocontainer.nanowar.ServletContainerListener</listener-class> </listener>
Activation of Request scope containers
<filter> <filter-name>NanoWar</filter-name> <filter-class>org.nanocontainer.nanowar.ServletRequestContainerFilter</filter-class> </filter>
The servlet container will instantiate these classes and send them events. When they receive events they will create containers in the proper hierarchy level and store them in the app/session/request contexts.
Important! You must define a filter-mapping for the servlets that you want to create request scope containers. See NanoWar WebWork for an example.
Scoped containers
The NanoWar component creates PicoContainer instances at the application, session and request level, using the following hierarchy:

As illustrated in the diagram, a new PicoContainer will be instantiated every time the following happens:
- The web application starts: a new PicoContainer will be created and stored in the ServletContext.
- A new session is created: a new PicoContainer (using the application level one as parent) will be created and stored in the HttpSession.
- A new request is created: a new PicoContainer (using the session level one as parent) will be created and stored in the ServletRequest.
The lifespan of the request level containers will be really short! However, instantiating a PicoContainer is a very light operation.
Supports multiple MVC web frameworks
NanoWar supports multiple Model View Controller (MVC) application frameworks:
NanoWar NanoWeb - our own tiny one
NanoWar Struts - enablers for Apache's Struts Framework
NanoWar WebWork - enablers for the excellent OpenSymphony WebWork
Please refer to the individual pages above for details on how each framework is supported to enable dependency injection using the scope PicoContainers.
