flybywire
flybywire

Reputation: 273502

small footprint dependency injection java

I am looking for a very lightweight dependency injection framework for java. With minimum possible dependencies and minimum features.

Just something along the following lines: receive a java.util.List of Classes, instantiate them and just auto-wire all the objects one into the other.

Upvotes: 3

Views: 3101

Answers (7)

toolkit
toolkit

Reputation: 50237

I would recommend Spring, since this can provide a small footprint when using only the core packages.

If you think Spring is overkill, then perhaps PicoContainer, or guice?

Upvotes: 10

Ermolai
Ermolai

Reputation: 323

Take a look at ActiveJ Inject.

It is a lightweight dependency injection library. It is optimized for performance and has no third-party dependencies.

It is much faster than Spring DI or Guice and it is much lighter. Check the benchmarks here

Upvotes: 0

jeorfevre
jeorfevre

Reputation: 2316

Take a look at dagger2, developped at google (forked of square's dagger1), for only 17kb jar.

  • Much less boilerplate than guice
  • compile time verification of injection (with explicit error message. That's something spring, guice does definitly not)
  • generate Facotries, codes upon compile. Very powerfull

dagger2 documentation dagger2 github dagger2 examples

Upvotes: 2

user1889543
user1889543

Reputation: 111

Silk DI is about 120K single jar file with no further runtime dependencies. It has a fluent binder interface like guice but is more flexible and allows to remove features you don't like. E.g. Collection or List injection can be added in a one liner.

Upvotes: 3

chrisapotek
chrisapotek

Reputation: 6227

I have been trying MentaContainer for less than a week now and I am satisfied by its clean and straightforward API. Instead of using XML or Annotations for the setup it uses a fluent API almost like a DSL which for me felt like like heaven because I am using it to build a small web container with IoC support. It provides a THREAD scope for the components which fits perfectly for the REQUEST scope of the web container. It is very lightweight so it may be what you need.

Upvotes: 2

user185947
user185947

Reputation:

Definitely look into Guice. Been using it for a year, and absolutely love it.

Upvotes: 0

Mani
Mani

Reputation: 91

Maybe you should have a look at Google Guice: http://code.google.com/p/google-guice/

Upvotes: 9

Related Questions