The Artima Developer Community
Sponsored Link

Java Buzz Forum
PicoContainer / NanoContainer

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jon Tirsen

Posts: 33
Nickname: tirsen
Registered: Apr, 2003

Jon Tirsen is a developer at Lecando AB working a lot with open source and agile methodologies
PicoContainer / NanoContainer Posted: Jun 27, 2003 12:40 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Jon Tirsen.
Original Post: PicoContainer / NanoContainer
Feed Title: jutopia
Feed URL: http://sedoparking.com/search/registrar.php?domain=®istrar=sedopark
Feed Description: Ramblings on Java, AOP, TDD, agile and so on. some like it jutopic!
Latest Java Buzz Posts
Latest Java Buzz Posts by Jon Tirsen
Latest Posts From jutopia

Advertisement
I've recently joined two new projects:
http://www.picocontainer.org
http://www.nanocontainer.org

The founders of the project are Paul (AltRMI, Enterprise Object Broker) and Aslak (XDoclet, MiddleGen). Actually they pair-programmed most of it at Paul's place and a lot of beer was involved. The end result: a neat, simplistic and wonderfully TDDed piece of work. Joe (SiteMesh, QDox), my unit-testing guru, is also in on it.

It's basically an Inversion-of-Control-container/framework/micro-kernel. Pico will be the simplistic micro-kernel and Nano will be a bunch of containers serving different purposes (most built on top of Pico).

I'm not an IoC-expert by any means, and, well, I didn't know much about it before chatting with Paul and Aslak. The cool (and quite controversial) thing is that Pico (at least by default) implements style 3 IoC, which means constructors are used to define dependencies. Smart!

I will implement some Nanning support in Nano so that aspects can define dependencies on services and the container will resolve them properly, the aspects will also be able to aspectify the components transparently. The details are far from finalized, just a bunch of semi-digested ideas. I'll give you a couple of use-cases though. An aspect implementing transparent persistence with Prevayler could retrieve it's Prevayler-instance just by declaring it in its constructor:

public class PrevaylerAspect {
  public PrevaylerAspect(Prevayler prevayler) { /* ... */ }
  /* ... */
}
A declarative transaction aspect could declare it's dependency on a TransactionManager by:
public class TransactionAspect {
  public TransactionAspect(TransactionManager transactionManager) { /* ... */ }
  /* ... */
}
Put these aspects along with their services in a container, Pico does it's work and all components are properly assembled:
PicoContainer pico = new HierarchicalPicoContainer.Default();

pico.registerComponent(RemoteTransactionManagerImpl.class);
pico.registerComponent(PicoPrevayler.class);
pico.registerComponent(PrevaylerAspect.class);
pico.registerComponent(TransactionAspect.class);

pico.start();
Neat and simple. No XML, no runtime attributes, no fuss.

Another great thing is that it's brilliant to mock-test the things. Say you want to mock-test your TransactionAspect to see that it actually demarcates it's transactions properly:

MockTransactionManager mockTransactionManager = new MockTransactionManager();
// ...set up expectations and so forth...
TransactionAspect transactionAspect = new TransactionAspect(mockTransactionManager);
AspectSystem aspectSystem = new AspectSystem();
aspectSystem.addAspect(transactionAspect);
TestObject testObject = (TestObject) aspectSystem.newInstance(TestObject.class);
// ...run your tests on your testObject...
mockTransactionManager.verify();

Check it, you'll like it!

Read: PicoContainer / NanoContainer

Topic: XP Celebrity Quiz Previous Topic   Next Topic Topic: Welcome back, JavaBlogs!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use