Petite
Petite is one great little IoC container and components manager. Petite is easy to use since it requires no external configuration; it is incredibly fast, lightweight and super-small; so anyone can quickly grasp how it works. Petite is quite extensible and open for customization; and non-invasive.

Quick Overview

The following bean shows some basic Petite usage:
1
@PetiteBean
2
public class Foo {
3
​
4
// dependency injected in the ctor
5
@PetiteInject
6
public Foo(ServiceOne one) {...}
7
​
8
// dependency injected in a field
9
@PetiteInject("serviceTwo")
10
ServiceTwo two;
11
​
12
// dependency injected with the method
13
@PetiteInject
14
public void injectService(ServiceThree three) {...}
15
​
16
// dependency injected with the method
17
public void injectService(
18
@PetiteInject ServiceFour four) {...}
19
​
20
// initialization method
21
@PetiteInitMethod
22
public void init() {...}
23
​
24
public void foo() {
25
}
26
}
Copied!
Foo is Petite bean that defines several injection points, for different depending services from the container. Put this bean in the classpath and let PetiteContainer find it and register as a bean. Or register it manually if you like that way more.

Why should I use it?

Petite is one of the lightest Java DI container around. Still, it supports sufficient most of features offered by other containers.
Here are the key features:
  • property, method and constructor injection points.
  • Instance life-cycle management, ordered initialization methods.
  • Adding external objects to container.
  • Wiring external objects with container's context.
  • Creating objects by container.
  • Automatic registration: no XML or code needed, just annotations.
  • Programmatic configuration: using plain Java.
  • Scopes: Prototype, Singleton and custom scopes.
  • Thread local scope for thread singletons.
  • HTTP session scope for session singletons.
  • Designed to be extended.
Last modified 8mo ago