3

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.

7 Answers 7

10

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?

Sign up to request clarification or add additional context in comments.

2 Comments

I'd recommend Spring with only using a BeanFactory implementation - much of Spring's "heavyweight" nature comes from using the ApplicationContext without people understanding what overhead (although cool features come with that overhead) the ApplicationContext adds on top of the BeanFactory.
PicoContainer answers exactly to the requirements
9

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

1 Comment

I second that. Guice is lightweight and very little intrusive.
3

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.

Comments

2

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.

Comments

2

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

Comments

0

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

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.